Skip to content

Commit c7c155d

Browse files
committed
fix(ui): fix init cascader focus
1 parent 7175681 commit c7c155d

File tree

1 file changed

+27
-6
lines changed
  • packages/ui/src/components/cascader

1 file changed

+27
-6
lines changed

packages/ui/src/components/cascader/List.tsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,33 @@ function List<V extends DId, T extends DCascaderItem<V>>(
7676
const shouldInitFocus = dRoot && isUndefined(dFocusItem);
7777

7878
const handleKeyDown = useEventCallback<ComboboxKeyDownRef>((key) => {
79-
if (isFocus || shouldInitFocus) {
80-
const focusNode = (node: AbstractTreeNode<V, T> | undefined) => {
81-
if (node) {
82-
onFocusChange(node);
83-
}
84-
};
79+
const focusNode = (node: AbstractTreeNode<V, T> | undefined) => {
80+
if (node) {
81+
onFocusChange(node);
82+
}
83+
};
84+
if (shouldInitFocus) {
85+
switch (key) {
86+
case 'next':
87+
focusNode(vsRef.current?.scrollToStart());
88+
break;
89+
90+
case 'prev':
91+
focusNode(vsRef.current?.scrollToEnd());
92+
break;
93+
94+
case 'first':
95+
focusNode(vsRef.current?.scrollToStart());
96+
break;
97+
98+
case 'last':
99+
focusNode(vsRef.current?.scrollToEnd());
100+
break;
101+
102+
default:
103+
break;
104+
}
105+
} else if (isFocus) {
85106
switch (key) {
86107
case 'next':
87108
focusNode(vsRef.current?.scrollToStep(1));

0 commit comments

Comments
 (0)