Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(comp:tree-select): do not deselect when reclicked #1070

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export function useSelectedState(
}

const changeSelected = (value: VKey[]) => {
if (!props.multiple && !value.length) {
return
}
setValue(value)
}

Expand Down
6 changes: 4 additions & 2 deletions packages/components/tree-select/src/content/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export default defineComponent({

const handleSelect = (selected: boolean, node: TreeSelectNode) => {
const { onSelect } = props
callEmit(onSelect, selected, node)

if (!props.multiple && selectedValue.value?.[0] !== node.key) {
callEmit(onSelect, selected, node)
}
handleNodeClick()
}

Expand Down Expand Up @@ -196,7 +199,6 @@ export default defineComponent({
virtual={virtual}
selectable={multiple ? 'multiple' : true}
selectedKeys={selectedValue.value}
selectedClearable={false}
searchValue={searchFn !== false ? inputValue.value : undefined}
searchFn={isFunction(searchFn) ? searchFn : undefined}
showLine={showLine}
Expand Down
22 changes: 0 additions & 22 deletions packages/components/tree/__tests__/tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,28 +462,6 @@ describe('Tree', () => {
expect(allNodes[1].classes()).toContain('ix-tree-node-selected')
})

test('selectedClearable work', async () => {
const onUpdateSelectedKeys = vi.fn()
const wrapper = TreeMount({
props: {
dataSource: simpleDataSource,
selectable: true,
selectedKeys: ['0'],
checkable: false,
'onUpdate:selectedKeys': onUpdateSelectedKeys,
selectedClearable: true,
},
})

const allNodes = wrapper.findAll('.ix-tree-node')
await allNodes[0].find('.ix-tree-node-content').trigger('click')
expect(onUpdateSelectedKeys).toBeCalledWith([])

await wrapper.setProps({ selectedClearable: false, selectedKeys: ['0'] })
await allNodes[0].find('.ix-tree-node-content').trigger('click')
expect(onUpdateSelectedKeys).toBeCalledWith(['0'])
})

test('blocked work', async () => {
const wrapper = TreeMount({
props: { blocked: true },
Expand Down
2 changes: 1 addition & 1 deletion packages/components/tree/src/composables/useSelectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function useSelectable(props: TreeProps, mergedNodeMap: ComputedRef<Map<V
if (isMultiple.value) {
selected ? tempKeys.splice(index, 1) : tempKeys.push(key)
} else {
tempKeys = selected && props.selectedClearable ? [] : [key]
tempKeys = selected ? [] : [key]
}

handleChange(selected, currNode.rawNode, tempKeys)
Expand Down
4 changes: 0 additions & 4 deletions packages/components/tree/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ export const treeProps = {
type: [Boolean, String] as PropType<boolean | 'multiple'>,
default: true,
},
selectedClearable: {
type: Boolean,
default: true,
},
showLine: {
type: Boolean,
default: undefined,
Expand Down