Skip to content

Commit

Permalink
fix(ui): fix init cascader focus
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejay97 committed Oct 25, 2022
1 parent 7175681 commit c7c155d
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions packages/ui/src/components/cascader/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,33 @@ function List<V extends DId, T extends DCascaderItem<V>>(
const shouldInitFocus = dRoot && isUndefined(dFocusItem);

const handleKeyDown = useEventCallback<ComboboxKeyDownRef>((key) => {
if (isFocus || shouldInitFocus) {
const focusNode = (node: AbstractTreeNode<V, T> | undefined) => {
if (node) {
onFocusChange(node);
}
};
const focusNode = (node: AbstractTreeNode<V, T> | undefined) => {
if (node) {
onFocusChange(node);
}
};
if (shouldInitFocus) {
switch (key) {
case 'next':
focusNode(vsRef.current?.scrollToStart());
break;

case 'prev':
focusNode(vsRef.current?.scrollToEnd());
break;

case 'first':
focusNode(vsRef.current?.scrollToStart());
break;

case 'last':
focusNode(vsRef.current?.scrollToEnd());
break;

default:
break;
}
} else if (isFocus) {
switch (key) {
case 'next':
focusNode(vsRef.current?.scrollToStep(1));
Expand Down

0 comments on commit c7c155d

Please # to comment.