-
Notifications
You must be signed in to change notification settings - Fork 141
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
chore: MultiComboBoxの内部処理を整理する #5338
base: master
Are you sure you want to change the base?
Conversation
…e-add-use-decorators
a7fbd27
to
8eddda4
Compare
commit: |
…e-add-use-decorators
…e-refactoring-MultiComboBox
…e-refactoring-MultiComboBox
…e-refactoring-MultiComboBox
…e-refactoring-MultiComboBox
onSelect?.(selected) | ||
onChangeSelected?.(selectedItems.concat(selected)) | ||
} else if (matchedSelectedItem.deletable !== false) { | ||
handleDelete(selected) |
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.
条件分岐を整理し、ネストが不要な状態にしています。
!disabled && | ||
!isFocused | ||
!isFocused && | ||
!(e.target as HTMLElement).closest('.smarthr-ui-MultiComboBox-deleteButton') |
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.
hasParentElementByClassName
はdomに対する検索になるため、他の条件と比べてかなり低速です。
そのため、まず他条件を調べてから必要な場合のみ実行するようにしています。
またhasParentElementByClassNameはやっている内容がほぼbuildinのclosestと同じ内容のため置き換えています
@@ -376,7 +368,7 @@ const ActualMultiComboBox = <T,>( | |||
const handleCompositionStartInput = useCallback(() => setIsComposing(true), []) | |||
const handleCompositionEndInput = useCallback(() => setIsComposing(false), []) | |||
const handleInputKeyDown = useCallback((e: KeyboardEvent<HTMLInputElement>) => { | |||
if (e.key === 'Down' || e.key === 'ArrowDown' || e.key === 'Up' || e.key === 'ArrowUp') { | |||
if (ARROW_UP_AND_DOWN_KEY_REGEX.test(e.key)) { |
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.
複雑なifでしたが、完全に同じ値に対するチェックだったため、正規表現一発に置き換えています
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.
LGTM!
関連URL
概要
変更内容
確認方法