Skip to content

Conversation

@uknmr
Copy link
Contributor

@uknmr uknmr commented Jul 11, 2025

関連URL

概要

Combobox が検索できることを伝えるために、Combobox の見た目としての Input と検索用の SearchInput を分けました。

変更内容

Before After
image image
  • 検索できることをアイコンで示すので、dropdownHelpMessage を削除
  • MultiCombobox の delete ボタンによる削除はやめました(そもそも機能もしていませんでした
  • 削除ボタンのフォーカス時に、Combobox 自体にフォーカスリングが表示されないように修正

やってないこと

  • Single と Multi で共通化出来そうな部分が多々あったのですが、力尽きました
  • テストも不十分ですが、力尽きました
  • Combobox が並んでいる時のフォーカス管理があやしいですが、実際にはほぼ発生しないため目をつむっています

確認方法

@uknmr uknmr requested a review from a team as a code owner July 11, 2025 03:21
@uknmr uknmr requested review from AtsushiM and schktjm and removed request for a team July 11, 2025 03:21
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 11, 2025

Open in StackBlitz

npm i https://pkg.pr.new/kufu/smarthr-ui@5790

commit: 796ee4b

@uknmr uknmr force-pushed the improve-Combobox-style branch from 7212c76 to 261c70c Compare July 11, 2025 03:40
@AtsushiM
Copy link
Member

AtsushiM commented Jul 14, 2025

検索できることをアイコンで示すので、dropdownHelpMessage を削除

これって どんな内容で検索すればいいか? などのヘルプとして使うものという認識だったんですが、本当に消して大丈夫です?
例えば社員番号、従業員名、部署が1アイテムに詰まっている場合 社員番号、氏名、部署で検索できます っていうヘルプメッセージを出している、みたいな使い方をしているプロダクトをいくつか知っています

Comment on lines +325 to +333
if (e.key === 'Enter' && !isFocused) {
// パネルが閉じている状態でEnterを押した場合、パネルを開く
e.preventDefault()
focus()
} else if (e.key === 'ArrowDown' && !isFocused) {
// パネルが閉じている状態で下矢印を押した場合、パネルを開く
e.preventDefault()
focus()
}
Copy link
Member

Choose a reason for hiding this comment

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

!isFocusedが何度も検証されていますし、if-else内の処理が完全に同一なのでまとめたいです。

// パネルが閉じている状態でEnter or 下矢印を押した場合、パネルを開く
if (!isFocused && /^(Enter|ArrowDown)$/.test(e.key)) {
  e.preventDefault()
  focus()
}

searchValue,
onSearchValueChange: setSearchValue,
onChangeInput,
onEscape: () => setIsFocused(false),
Copy link
Member

Choose a reason for hiding this comment

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

今のところ、useCallbackする方針なのでやってもらえると 🙏
(再レンダリングの問題が起きる可能性は少ないですが、後々置きた場合の調査コストを考えるとやってあるほうが楽なので... 🙇 )

Comment on lines +277 to +288
if (relatedTarget) {
const comparison = currentTarget.compareDocumentPosition(relatedTarget)

const highlightedRef = useRef(highlighted)
// 順方向の場合のみ、パネルを開く
// DOCUMENT_POSITION_PRECEDING (2) = 前の要素が現在の要素より前にある
if (comparison & Node.DOCUMENT_POSITION_PRECEDING) {
focus()
}
} else {
// マウスクリックまたは初回フォーカスの場合は開く
focus()
}
Copy link
Member

Choose a reason for hiding this comment

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

if-elseのネストをせず1階層、かつ一つのifで処理をまとめられるので調整したいです。

if (
  // マウスクリックまたは初回フォーカスの場合は開く
  !relatedTarget ||
  // 順方向の場合のみ、パネルを開く
  // DOCUMENT_POSITION_PRECEDING (2) = 前の要素が現在の要素より前にある
  (currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_PRECEDING)
) {
  focus()
}

setInputValueIfUncontrolled('')
const handleClick = useMemo(() => {
if (disabled) {
return
Copy link
Member

@AtsushiM AtsushiM Jul 14, 2025

Choose a reason for hiding this comment

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

好みの問題もありますが、このreturnは早期returnというよりは onClickで何も処理させない ための早期returnなのでundefinedであることに意味がありそうです。
なので return undefinedしてもらえると他開発者が読むときに理解しやすそう

}, [disabled, focus])
const actualOnChangeInput = useMemo(() => {
const handlers = [onChange, onChangeInput].filter((h) => !!h)
const handlers = [onChange].filter((h) => !!h)
Copy link
Member

Choose a reason for hiding this comment

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

onChangeInputがなくなり、配列である必要性がなくなっています。
関連ロジックを見直したほうが良さそう

Copy link
Contributor

@Qs-F Qs-F left a comment

Choose a reason for hiding this comment

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

これって どんな内容で検索すればいいか? などのヘルプとして使うものという認識だったんですが、本当に消して大丈夫です?
例えば社員番号、従業員名、部署が1アイテムに詰まっている場合 社員番号、氏名、部署で検索できます っていうヘルプメッセージを出している、みたいな使い方をしているプロダクトをいくつか知っています

これは本来SearchInputの役割なので、dropdownHelpMessageの役割ではない認識です!
なので検索対象をSearchInputのTooltipに渡せるようにしたいです!

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.

4 participants