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

undefined value for <USelect> option is not honored, label is used instead #1702

Closed
Labels
bug Something isn't working

Comments

@TheAlexLichter
Copy link
Member

TheAlexLichter commented Apr 21, 2024

Environment

Stackblitz

Version

2.15.2

Reproduction

https://stackblitz.com/edit/nuxt-ui-1702?file=package-lock.json

  1. Select the first option
  2. See that select is not undefined.

Description

When creating options for the USelect component and providing a value purposefully as undefined, the custom value will not be considered and the label value will be used.

image

Additional context

No response

Logs

No response

@TheAlexLichter TheAlexLichter added the bug Something isn't working label Apr 21, 2024
@moshetanzer
Copy link
Collaborator

Hey @manniL,

Nice to see you around here 😄

This seems to have been implemented on purpose:

https://github.com/nuxt/ui/blob/8d9d9736ba6a0f25d8cd0b60e1ca50b072a3d176/src/runtime/components/forms/Select.vue#L201C1-L207C6

I hear you though, have the following immediate solution (funcs may not be nessaccry at all):

    const guessOptionValue = (option: any) => {
  return get(option, props.valueAttribute, '')
}

const guessOptionText = (option: any) => {
  return get(option, props.optionAttribute, '')
}

Guess if important now you can patch in the meantime. Else @benjamincanac what are your thoghts?

Copy link
Member

I guess we can remove the default values indeed, I honestly don't remember why we added those 😅

Copy link
Member

I've been looking at this and it doesn't seem related to default values. You need to have an empty <option> for this to work which can be automatically added by using the placeholder prop: https://ui.nuxt.com/components/select#placeholder.

@manniL It might be easier to achieve what you want using the SelectMenu component.

@moshetanzer
Copy link
Collaborator

@benjamincanac still feel that one might have undefined value in array they pass on purpose, surely we should remove the guess functions?

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