-
Notifications
You must be signed in to change notification settings - Fork 126
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
MenuItem in any level #2749
MenuItem in any level #2749
Conversation
82464c3
to
f3f609e
Compare
c949029
to
8275fab
Compare
@zhzz А почему это изменение для |
51b32b4
to
f122a62
Compare
packages/react-ui/internal/InternalMenu/__tests__/InternalMenu-test.tsx
Outdated
Show resolved
Hide resolved
private highlight = (key: string | undefined) => { | ||
this.setState({ highlightedKey: key }); | ||
getRootNode(this)?.focus(); | ||
}; | ||
|
||
private unhighlight = () => { | ||
this.setState({ highlightedIndex: -1 }); | ||
}; | ||
|
||
private move(step: number) { | ||
this.setState((state, props) => { | ||
const children = childrenToArray(props.children); | ||
if (!children.some(isActiveElement)) { | ||
return null; | ||
} | ||
let index = state.highlightedIndex; | ||
do { | ||
index += step; | ||
if (!props.cyclicSelection && (index < 0 || index > children.length)) { | ||
return null; | ||
} | ||
const menuItems = this.menuItems; | ||
if (!menuItems.length) { | ||
return; | ||
} | ||
|
||
if (index < 0) { | ||
index = children.length - 1; | ||
} else if (index > children.length) { | ||
index = 0; | ||
} | ||
let highlightedIndex = -1; | ||
if (this.state.highlightedKey) { | ||
highlightedIndex = this.menuItems.findIndex((item) => item.key === this.state.highlightedKey); | ||
} | ||
|
||
const child = children[index]; | ||
if (isActiveElement(child)) { | ||
return { highlightedIndex: index }; | ||
} | ||
} while (index !== state.highlightedIndex); | ||
return null; | ||
}, this.scrollToSelected); | ||
const newHighlightedIndex = highlightedIndex + step; | ||
if (newHighlightedIndex < 0) { | ||
this.setState({ highlightedKey: menuItems[menuItems.length - 1].key }); | ||
this.scrollToBottom(); | ||
return; | ||
} | ||
|
||
if (newHighlightedIndex >= menuItems.length) { | ||
this.setState({ highlightedKey: menuItems[0].key }); | ||
this.scrollToTop(); | ||
return; | ||
} | ||
|
||
this.setState({ highlightedKey: menuItems[newHighlightedIndex].key }); | ||
|
||
switch (newHighlightedIndex) { | ||
case 0: | ||
this.scrollToTop(); | ||
break; | ||
case menuItems.length - 1: | ||
this.scrollToBottom(); | ||
break; | ||
default: | ||
this.scrollToSelected(); | ||
} | ||
} | ||
|
||
private scrollToSelected = () => { | ||
if (this.scrollContainer && this.highlighted) { | ||
this.scrollContainer.scrollTo(getRootNode(this.highlighted)); | ||
} | ||
}; | ||
|
||
private scrollToTop = () => { | ||
if (this.scrollContainer) { | ||
this.scrollContainer.scrollToTop(); | ||
} | ||
}; | ||
|
||
private scrollToBottom = () => { | ||
if (this.scrollContainer) { | ||
this.scrollContainer.scrollToBottom(); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Эта логика идентична логике из Menu
. Нужно переиспользовать её. Это потенциальное место для большого количества багов.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Про идентичность согласна.
Но на будущее есть задача про унификацию меню-подобных компонентов, в рамках которой и хотела избавиться от копипасты.
Подумаю, что и как можно сделать на текущем этапе.
packages/react-ui/internal/CustomComboBox/CustomComboBoxReducer.tsx
Outdated
Show resolved
Hide resolved
Нужно удалить лишние комментарии. |
Везде где используются значения из |
Актуальный пр