-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix(select): prevent default browser error UI from appearing #4281
base: canary
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: f02168d The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@chirokas is attempting to deploy a commit to the NextUI Inc Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThis pull request introduces updates to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
packages/components/select/__tests__/select.test.tsx (1)
1473-1481
: Useconst
instead oflet
for variables that are not reassignedIn line 1473,
let {getByTestId} = render(...)
should be declared withconst
sincegetByTestId
is not reassigned within the scope.Apply the following diff to improve code consistency:
- let {getByTestId} = render( + const {getByTestId} = render(packages/components/select/src/hidden-select.tsx (1)
Line range hint
106-122
: Incorrect handling of multiple selections in<select>
elementWhen
selectionMode
is"multiple"
, setting thevalue
prop to an array ([...state.selectedKeys].map((k) => String(k))
) is not standard for native HTML<select>
elements. Thevalue
attribute expects a string, and for multiple selections, each<option>
should have aselected
attribute if it is selected.Additionally, in the
onChange
handler,e.target.value
returns a string for single selections. For multiple selections, you need to usee.target.selectedOptions
to retrieve all selected values.Please update the code to correctly handle multiple selections:
Instead of setting
value
inselectProps
, add theselected
attribute to each<option>
element based on whether itsvalue
is instate.selectedKeys
:<option key={item.key} value={item.key} selected={state.selectedKeys.has(item.key)} > {item.textValue} </option>Modify the
onChange
handler to handle multiple selections:- onChange: (e: React.ChangeEvent<HTMLSelectElement>) => { - state.setSelectedKeys(e.target.value); - onChange?.(e); - }, + onChange: (e: React.ChangeEvent<HTMLSelectElement>) => { + if (selectionMode === "multiple") { + const selectedValues = Array.from(e.target.selectedOptions).map((option) => option.value); + state.setSelectedKeys(new Set(selectedValues)); + } else { + state.setSelectedKeys(new Set([e.target.value])); + } + onChange?.(e); + },This ensures that the hidden
<select>
element accurately reflects the selected values and that the form submission works correctly with multiple selections.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (4)
.changeset/quick-buses-kick.md
(1 hunks)packages/components/select/__tests__/select.test.tsx
(5 hunks)packages/components/select/src/hidden-select.tsx
(1 hunks)packages/hooks/use-aria-multiselect/src/use-multiselect-state.ts
(1 hunks)
🔇 Additional comments (3)
packages/components/select/__tests__/select.test.tsx (2)
1182-1355
: Tests for validationBehavior="native"
are comprehensive and well-implemented
The test cases effectively cover scenarios for:
- Required field validation (
isRequired
) - Custom validation functions (
validate
) - Server-side validation handling
- Clearing validation state on form reset
These tests ensure that the Select
component behaves correctly under native validation behavior.
Line range hint 1401-1493
: Tests for validationBehavior="aria"
are thorough and correctly handle validation states
The test cases appropriately handle:
- Required field validation with custom server errors
- Custom validation functions with ARIA validation behavior
- Server-side validation handling and clearing of validation messages upon user action
The implementation ensures that the Select
component provides accessible validation feedback when using ARIA validation behaviors.
.changeset/quick-buses-kick.md (1)
1-6
: Changeset is correctly formatted and includes appropriate summary
The changeset properly specifies patch updates for @nextui-org/select
and @nextui-org/use-aria-multiselect
. The summary message clearly states the purpose of the changes, addressing issue #3913.
@@ -87,6 +87,8 @@ export function useMultiSelectState<T extends object>({ | |||
if (props.selectionMode === "single") { | |||
triggerState.close(); | |||
} | |||
|
|||
validationState.commitValidation(); |
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.
Potential reference error: validationState
is used before it is defined
The call to validationState.commitValidation()
inside onSelectionChange
may cause a runtime error because validationState
is declared after listState
. Since validationState
is not yet initialized when onSelectionChange
is created, it will be undefined
at the time of the function's execution.
To resolve this issue, consider initializing validationState
before listState
, or restructure the code so that validationState
is accessible within onSelectionChange
without causing a reference error.
Closes #3913
Original: #3984
📝 Description
See #3913 (comment)
⛳️ Current behavior (updates)
🚀 New behavior
💣 Is this a breaking change (Yes/No):
📝 Additional Information
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores