Skip to content

[Select] Fix mismatch with hidden native select #1421

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

Merged
merged 3 commits into from
May 25, 2022

Conversation

benoitgrelard
Copy link
Contributor

@benoitgrelard benoitgrelard commented May 25, 2022

Closes #1223

Note: easier to review without whitespace

@benoitgrelard benoitgrelard requested a review from andy-hook as a code owner May 25, 2022 11:59
Comment on lines +1057 to 1064
const nativeOption = React.useMemo(
() => (
<option key={itemContext.value} value={itemContext.value} disabled={itemContext.disabled}>
{textContent}
</option>
),
[itemContext.disabled, itemContext.value, textContent]
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am building the option element directly here, this has 2 advantages in my opinion:

  • it makes it more clear/explicit what this is used for, seeing the native option collocated here
  • it means I don't need to invent a new data structure like { value, label: textContent, disabled } just to pass it up and interpolate it higher up.

Copy link
Contributor

Choose a reason for hiding this comment

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

haha yeah.. my initial gut reaction was to ask why we don't render closer, I think I'm just conditioned by typically seeing these built closer to the render. But:

it means I don't need to invent a new data structure like { value, label: textContent, disabled } just to pass it up and interpolate it higher up.

Actually makes much more sense, it's easier to follow when you realise the alternative is just going around the houses for no great reason.

Copy link
Contributor

@andy-hook andy-hook left a comment

Choose a reason for hiding this comment

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

I like this, seems clear enough to me given our shared understanding of the problem. The comments are mostly nits, I think we should add a bit more context for the future with a comment or two though 🙏

Comment on lines +1057 to 1064
const nativeOption = React.useMemo(
() => (
<option key={itemContext.value} value={itemContext.value} disabled={itemContext.disabled}>
{textContent}
</option>
),
[itemContext.disabled, itemContext.value, textContent]
);
Copy link
Contributor

Choose a reason for hiding this comment

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

haha yeah.. my initial gut reaction was to ask why we don't render closer, I think I'm just conditioned by typically seeing these built closer to the render. But:

it means I don't need to invent a new data structure like { value, label: textContent, disabled } just to pass it up and interpolate it higher up.

Actually makes much more sense, it's easier to follow when you realise the alternative is just going around the houses for no great reason.

@benoitgrelard benoitgrelard merged commit f3e79bc into main May 25, 2022
@benoitgrelard benoitgrelard deleted the select-native-initial-value branch May 25, 2022 14:26
luisorbaiceta pushed a commit to luisorbaiceta/primitives that referenced this pull request Jul 21, 2022
* [Select] Fix mismatch with hidden native select

Closes radix-ui#1223

* PR feedback

* Update packages/react/select/src/Select.tsx

Co-authored-by: Andy Hook <[email protected]>

Co-authored-by: Andy Hook <[email protected]>
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.

[Select] Underlying native select has wrong default value
2 participants