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

fix: accept boolean and numeric item values #4064

Merged
merged 2 commits into from
Jun 19, 2022
Merged

fix: accept boolean and numeric item values #4064

merged 2 commits into from
Jun 19, 2022

Conversation

cromoteca
Copy link
Contributor

Description

When the vaadin-select component receives a value which is not a string, it should be able to find the corresponding item anyway. This fix simply convert the new value to string before searching for it. This will also allow Hilla to bind selects to boolean and integers.

Fixes #4059

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

packages/select/src/vaadin-select.js Outdated Show resolved Hide resolved
packages/select/test/select.test.js Outdated Show resolved Hide resolved
packages/select/test/select.test.js Outdated Show resolved Hide resolved
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan web-padawan changed the title fix: let select accept non-string values fix: accept boolean and numeric item values Jun 19, 2022
Copy link
Member

@web-padawan web-padawan left a comment

Choose a reason for hiding this comment

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

LGTM. I'm not sure if using true and false as vaadin-item values is something we should promote in the docs (personally, I would use a checkbox). But it's a relatively small feature so 🤷‍♂️

@cromoteca
Copy link
Contributor Author

cromoteca commented Jun 19, 2022

I agree with you. The need came from vaadin/hilla#177. Might be a bit more useful with numbers anyway.

@web-padawan web-padawan merged commit 618458d into vaadin:master Jun 19, 2022
web-padawan pushed a commit that referenced this pull request Jun 19, 2022
@tomivirkki
Copy link
Member

Is a similar change planned for components other than <vaadin-select>?

For example, in the following cases:

<vaadin-radio-group label="Travel class">
  <vaadin-radio-button value="1" label="Economy"></vaadin-radio-button>
  <vaadin-radio-button value="2" label="Business"></vaadin-radio-button>
</vaadin-radio-group>
comboBox.items = [
  {
    label: 'foo',
    value: '1',
  },
  {
    label: 'bar',
    value: '2',
  },
];

...this works: component.value = '1'
but this doesn't: component.value = 1

@web-padawan
Copy link
Member

There is an issue for supporting array of numbers in vaadin-combo-box: #1379

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

Successfully merging this pull request may close these issues.

<vaadin-select> with renderer cannot be bound to integer or boolean
4 participants