Skip to content
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: SingleComboBoxの内部ロジックを整理する #5337

Merged
merged 70 commits into from
Feb 26, 2025

Conversation

AtsushiM
Copy link
Member

関連URL

概要

変更内容

確認方法

@AtsushiM AtsushiM marked this pull request as draft February 12, 2025 00:40
} else if (!selectedItem && defaultItem) {
if (onSelect) onSelect(defaultItem)
} else if (!selectedItem) {
selectDefaultItem()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectDefaultItemにdefaultItemのある無しなどのロジックは押し込められているため、調整しています

Comment on lines -335 to +350
if (selectedItem) {
setInputValue(innerText(selectedItem.label))
} else {
setInputValue('')
}
setInputValue(selectedItem ? innerText(selectedItem.label) : '')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

絶対にsetInputValueは実行されるため、引数のみを条件分岐することでわかりやすくしました

Comment on lines -324 to +346
useCallback(() => {
if (!isFocused && onSelect && !selectedItem && defaultItem) {
onSelect(defaultItem)
}
}, [isFocused, selectedItem, onSelect, defaultItem]),
useCallback(() => {
unfocus()
}, [unfocus]),
isFocused || selectedItem ? NOOP : selectDefaultItem,
unfocus,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

無意味にmemo化されていたので調整しています。

if (!isExpanded) {
setIsExpanded(true)
}
}
handleListBoxKeyDown(e)
},
[isComposing, isExpanded, setIsExpanded, unfocus, handleListBoxKeyDown],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setIsExpandedはuseStateのsetterなので依存関係に含める必要がありません

if (isExpanded) {
e.stopPropagation()
setIsExpanded(false)
}
} else if (e.key === 'Tab') {
unfocus()
} else {
if (['Down', 'ArrowDown', 'Up', 'ArrowUp'].includes(e.key)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

配列をチェックするより、正規表現一発のほうが明らかに高速のため置き換えています

@AtsushiM AtsushiM marked this pull request as ready for review February 25, 2025 22:31
</button>
)
}

const MemoizedNewIconWithText = React.memo<{ label: ReactNode }>(({ label }) => (
<FaPlusCircleIcon color="TEXT_LINK" text={<Text color="TEXT_LINK">「{label}」を追加</Text>} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FaPlusCircleIconが旧名称でdeprecatedなのでこのタイミングで FaCirclePlusIconにしたい...!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

やりますか

Copy link
Contributor

@masa0527 masa0527 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一点コメントしましたが他は問題ないかなと思います

@AtsushiM AtsushiM merged commit 8b8c90b into master Feb 26, 2025
11 checks passed
@AtsushiM AtsushiM deleted the chore-refactoring-SingleComboBox branch February 26, 2025 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants