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

[Bug]: Select component ignores "selected" property on page load #18164

Open
2 tasks done
thekevinhunt opened this issue Nov 26, 2024 · 4 comments
Open
2 tasks done

[Bug]: Select component ignores "selected" property on page load #18164

thekevinhunt opened this issue Nov 26, 2024 · 4 comments
Assignees
Labels

Comments

@thekevinhunt
Copy link

Package

@carbon/web-components

Browser

Chrome

Package version

v2.18.0

React version

No response

Description

When using the cds-select component and including "selected" on a cds-select-item element, the option is not selected on page load. Interestingly, if you modify the DOM in the developer toolbar to add "selected" AFTER the page initially loads, it properly selects the element.

Interestingly, the "disabled" property doesn't have the same problem on cds-select-item elements.

Reproduction/example

https://stackblitz.com/github/carbon-design-system/carbon/tree/main/packages/web-components/examples/components/select?file=index.html

Steps to reproduce

  1. Use the existing stackblitz build provided in the docs (https://web-components.carbondesignsystem.com/?path=/docs/components-select--overview)
  2. Simply add "selected" as a property to any cds-select-item in the index.html file.
  3. The page will automatically reload, but the option won't be selected
  4. Edit the live HTML directly in the web developer tools and the option will get selected fine

Suggested Severity

Severity 2 = User cannot complete task, and/or no workaround within the user experience of a given component.

Application/PAL

IBM Industry Compliance PIMS Portal

Code of Conduct

@sstrubberg sstrubberg moved this to 🕵️‍♀️ Triage in Design System Dec 10, 2024
@alisonjoseph alisonjoseph added severity: 2 https://ibm.biz/carbon-severity and removed package: @carbon/web-components @carbon/web-components labels Dec 11, 2024
@alisonjoseph alisonjoseph moved this from 🕵️‍♀️ Triage to ⏱ Backlog in Design System Dec 11, 2024
@ariellalgilmore
Copy link
Member

ariellalgilmore commented Dec 11, 2024

Hi @thekevinhunt did you try setting the value on cds-select like the following:

    <cds-select
      helper-text="Optional helper text"
      label-text="Select"
      placeholder="Optional placeholder text"
      value="cloudFoundry" <---------
    >
      <cds-select-item-group label="Category 1">
        <cds-select-item value="all">Option 1</cds-select-item>
        <cds-select-item value="cloudFoundry">Option 2</cds-select-item>
      </cds-select-item-group>
      <cds-select-item-group label="Category 2">
        <cds-select-item value="staging">Option 3</cds-select-item>
        <cds-select-item value="dea">Option 4</cds-select-item>
        <cds-select-item value="router">Option 5</cds-select-item>
      </cds-select-item-group>
    </cds-select>

On page load i see the select now starting with "Option 2"

@thekevinhunt
Copy link
Author

@ariellalgilmore ugh, I missed that value setting completely... but to my credit, that's not intuitive at all when you're used to the normal HTML select, and the misdirect of the documentation listing a "selected" setting for cds-select-item, combined with the "value" setting not being documented very clearly.

It's working like I expect, knowing this now.

If nothing else, I suggest removing the "selected" setting documentation since it apparently doesn't do anything, and making the "value" setting documentation not that it's aligned with what people would expect "selected" to do.

@ariellalgilmore
Copy link
Member

Thanks for the feedback! Will reference this, so it gets updated in the parity issue #17931

@makafsal
Copy link
Member

makafsal commented Jan 9, 2025

@ariellalgilmore I agree with @thekevinhunt because, from the HTML perspective, our intuition would be to use the selected attribute instead of the value attribute. So, we can make both available to users to choose between value and selected at their convenience.

Value Selected Placeholder RESULT
Value
Selected
Placeholder
Value
Value
Selected
Value

@github-project-automation github-project-automation bot moved this to Needs triage 🧐 in Carbon for IBM Products Jan 9, 2025
@elycheea elycheea moved this from Needs triage 🧐 to Backlog 🌋 in Carbon for IBM Products Jan 9, 2025
@makafsal makafsal moved this from ⏱ Backlog to 🏗 In Progress in Design System Jan 9, 2025
@makafsal makafsal moved this from Backlog 🌋 to In progress in Carbon for IBM Products Jan 9, 2025
@makafsal makafsal moved this from 🏗 In Progress to 🚦 In Review in Design System Jan 17, 2025
@makafsal makafsal moved this from In progress to Needs review 👋 in Carbon for IBM Products Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Needs review 👋
Status: 🚦 In Review
Development

No branches or pull requests

5 participants