-
-
Notifications
You must be signed in to change notification settings - Fork 104
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 component to handle empty string values for keyboard #979
fix: select component to handle empty string values for keyboard #979
Conversation
…ard navigation - Updated `SelectTriggerState` to correctly handle `highlightedValue` as a valid empty string. - Introduced `generateTestId` and `getTestId` functions to ensure consistent test ids for select items, accommodating empty strings and null values. - Modified multiple test files to utilize the new test id generation logic. - Updated demo components to include options with empty string values and disabled attribute
🦋 Changeset detectedLatest commit: 221b20e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
Hey @max-got thanks a ton for digging into this. I think it's a bad practice to have an empty string as a value of one of the options as it makes it indistinguishable from an item not being selected at all. When you open the select, it has a value selected, but the placeholder is shown, and the I'm fine with this being added, but we won't be demonstrating it in the main demo or showing any examples of it. It will be more of a case of if you really want to do this, it's possible, but there are more explicit ways it should probably be done (i.e. using |
Totally fair point. I read up a bit on
And to:
Maybe we can think about it a bit? I will revert the demo example For example the following is closer to the const themes = [
+ { value: "", label: "Select a theme" },
{ value: "light-monochrome", label: "Light Monochrome" },
{ value: "dark-green", label: "Dark Green" },
//...
];
let value = $state<string>("");
const selectedLabel = $derived(
- value ? themes.find((theme) => theme.value === value)?.label : "Select a Theme"
+ value ? themes.find((theme) => theme.value === value)?.label : themes[0].label
); but the bottom line is, i don't know either 🤷♂️ |
Yeah, I see their example does do that... interesting 🤔 For now, let's leave it off our main example here, but I'll take it under consideration as the "default" experience. If you think it would be beneficial, we could add another example towards the bottom in its own docs section showcasing that capability! |
I don't think there is a need for extra docs/section. There will be issues/questions if something is off |
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.
Thank you!
Closes #977
Fixed empty value keyboard selection for
Select
Component.The diff is very large, but just because i've added an empty value option in the items array in
packages/tests/src/tests/select/select.test.ts
file.Added a few tests as well + enhanced the Components for the Docs to showcase
disabled
options and an option with an empty (""
) value. Tho that can be further enhanced, to showcase the possibilities even further.I have added test helpers in
packages/tests/src/tests/helpers/select.ts
because i needed a way to generate a valid testId for the select components. Because there are 3 Components + the test file, it felt right to abstract them away in a helper. I dont't know if that this is your desired approach. Let me know if there is something wrong.