Skip to content
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

[EUI] Setting the value to undefined does not select the blank option. #4427

Closed
cnasikas opened this issue Jan 15, 2021 · 3 comments · Fixed by #4428
Closed

[EUI] Setting the value to undefined does not select the blank option. #4427

cnasikas opened this issue Jan 15, 2021 · 3 comments · Fixed by #4428

Comments

@cnasikas
Copy link
Member

A EuiSelect with hasNoInitialSelection creates a black option at the begging of the select. This is very useful when you don't want to preselect a value. If you select a value, and then you set it to undefined the black option is not selected. Example:

<EuiSelect
  fullWidth
  data-test-subj="subcategorySelect"
  hasNoInitialSelection
  options={subcategoriesOptions}
  value={subcategory ?? undefined}
  onChange={(e) => {// set the subcategory}}
/>

If I change value={subcategory ?? undefined} to value={subcategory ?? ''} (empty string) then the blank option is selected.

Steps to reproduce:

  1. Select an option.
  2. Make the value undefined. Example: You press a button that sets the value to undefined.

I think the component should handle both cases. Thanks!

@elasticmachine
Copy link
Collaborator

Pinging @elastic/eui-design (EUI)

@snide
Copy link
Contributor

snide commented Jan 15, 2021

EuiSelect is just a regular HTML select in disguise. Regular selects do not allow undefined values. If you want one, you need to pass them as an empty option in your array and assign it. Read issue too quickly in the morning, but this is why it happens. It's actually an empty string in disguise. :)

@snide
Copy link
Contributor

snide commented Jan 15, 2021

Sorry, I read this one too quickly. I forgot about the extra prop we add! It probably makes sense that it can handle both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants