Skip to content

Commit

Permalink
fix(comp:tree-select): do not deselect when reclicked (#1070)
Browse files Browse the repository at this point in the history
  • Loading branch information
hangboss1761 committed Aug 11, 2022
1 parent 3f8b5a5 commit 1a11051
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 29 deletions.
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

0 comments on commit 1a11051

Please sign in to comment.