Repository navigation
fix: prevent default scrolling on arrow navigation and handle RTL direction #345
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,19 +248,32 @@ const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>( | |
| const nextOption = validOptions[nextIndex]; | ||
|
|
||
| if (nextOption && nextOption.value !== rawValue) { | ||
| const optionIndex = segmentedOptions.indexOf(nextOption); | ||
| containerRef.current | ||
| ?.querySelectorAll<HTMLInputElement>(`input.${prefixCls}-item-input`) | ||
| [optionIndex]?.focus(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| setRawValue(nextOption.value); | ||
| onChange?.(nextOption.value); | ||
| } | ||
| }; | ||
|
|
||
| const handleKeyDown = (event: React.KeyboardEvent) => { | ||
| const isRtl = direction === 'rtl'; | ||
| switch (event.key) { | ||
| case 'ArrowLeft': | ||
| event.preventDefault(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 切换选项时同步移动焦点。 当 🤖 Prompt for AI Agents |
||
| onOffset(isRtl ? 1 : -1); | ||
| break; | ||
| case 'ArrowRight': | ||
| event.preventDefault(); | ||
| onOffset(isRtl ? -1 : 1); | ||
| break; | ||
| case 'ArrowUp': | ||
| event.preventDefault(); | ||
| onOffset(-1); | ||
| break; | ||
| case 'ArrowRight': | ||
| case 'ArrowDown': | ||
| event.preventDefault(); | ||
| onOffset(1); | ||
| break; | ||
| } | ||
|
|
||
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.
Script executed:
Repository: react-component/segmented
Length of output: 7027
Script executed:
Repository: react-component/segmented
Length of output: 10869
Script executed:
Repository: react-component/segmented
Length of output: 8022
请按外层选项保存并聚焦对应的 radio。
itemRender可以返回任意ReactNode。如果它保留itemContent并添加嵌套Segmented,嵌套控件的 radio 也会位于外层containerRef内,并匹配${prefixCls}-item-input。箭头导航按
segmentedOptions的索引读取整个容器的 radio 列表。对于第二个外层选项,列表可能是“外层第一个 radio、嵌套 radio、外层第二个 radio”。此时索引1会聚焦嵌套 radio,而不是选中的外层选项。调整
setRawValue的执行时机不能修复这个范围错误。焦点必须绑定到对应的外层选项。Suggested fix