Skip to content

refactor(selector): not hiding the first option anymore #4020

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

Open
wants to merge 45 commits into
base: main
Choose a base branch
from

Conversation

mfranzke
Copy link
Collaborator

@mfranzke mfranzke commented Apr 4, 2025

Proposed changes

  • it's inconsistent in between browsers (Safari would still display that option[hidden])
  • it's inconsistent and incorrect for regular select-HTML-elements, as those would actually mark the first option as checked as well, whereas this is actually the selected one (gets transmitted in form submits etc.)
  • In case that somebody would like to use floating labels or placeholder, there should be an option that the users could set to "unselect" all selectable options, or in other words "reset" any other selection. We wouldn't provide this possibility at the moment anyhow.

Resolves #4019

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (fix on existing components or architectural decisions)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Further comments

it's inconsistent in between browsers and we should only use it for placeholders or floating labels
@mfranzke mfranzke requested a review from nmerget as a code owner April 4, 2025 09:16
@mfranzke mfranzke linked an issue Apr 4, 2025 that may be closed by this pull request
7 tasks
@mfranzke mfranzke self-assigned this Apr 4, 2025
Copy link
Contributor

github-actions bot commented Apr 4, 2025

@mfranzke mfranzke added the 🍄🆙improvement New feature or request label Apr 4, 2025
@github-actions github-actions bot added the 🧱components Changes inside components folder label Apr 4, 2025
@mfranzke mfranzke requested review from Copilot and removed request for nmerget April 4, 2025 09:16
@mfranzke mfranzke moved this to 🏗 In development in UX Engineering Team Backlog Apr 4, 2025
@mfranzke mfranzke added the 🐛bug Something isn't working label Apr 4, 2025
Copilot

This comment was marked as outdated.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mfranzke mfranzke added this to the 2.0.0 milestone Apr 4, 2025
@mfranzke mfranzke changed the title refactor: let's not hide the first element in the select anymore refactor(selector): let's not hide the first element in the select anymore Apr 4, 2025
@mfranzke mfranzke changed the title refactor(selector): let's not hide the first element in the select anymore refactor(selector): let's not hide the first element anymore Apr 4, 2025
@mfranzke mfranzke changed the title refactor(selector): let's not hide the first element anymore refactor(selector): let's not hide the first option anymore Apr 4, 2025
@mfranzke mfranzke changed the title refactor(selector): let's not hide the first option anymore refactor(selector): not hiding the first option anymore Apr 4, 2025
@mfranzke mfranzke modified the milestones: 2.0.0, 2.1.0 Apr 15, 2025
@github-actions github-actions bot added the 📦foundations Changes inside foundations folder label Apr 17, 2025
@leape leape removed this from Roadmap May 18, 2025
mfranzke and others added 25 commits June 30, 2025 17:55
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This reverts commit 88cea12.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@mfranzke mfranzke requested a review from Copilot July 2, 2025 13:46
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors how the first <option> placeholder is handled by removing the hidden attribute (which had inconsistent behavior across browsers) and instead using a .placeholder CSS class to control styling and visibility. It conditionally renders this placeholder option in the component, updates related selectors in SCSS, and refreshes all snapshots to match the new behavior.

  • Replace [hidden] filtering in CSS with .placeholder
  • Render placeholder option only when needed and update fallback logic
  • Refresh snapshots to reflect the first option no longer being hidden

Reviewed Changes

Copilot reviewed 14 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
showcases/screen-reader/snapshots/windows/chromium/DBSelect-default-1.txt Updated screen reader snapshot to reflect placeholder option behavior
packages/components/src/styles/internal/_form-components.scss Switched :not([hidden]) to :not(.placeholder) in focus selector
packages/components/src/components/select/select.scss Updated :not([hidden]) filter to .placeholder class
packages/components/src/components/select/select.lite.tsx Conditionally render placeholder <option> and changed fallback logic
packages/components/src/components/select/index.html Updated example to use .placeholder class for first <option>
snapshots/select/** Updated ARIA snapshots across browsers to match new option behavior

@@ -296,7 +298,7 @@ export default function DBSelect(props: DBSelectProps) {
</Show>
</select>
<span id={state._placeholderId}>
{props.placeholder ?? props.label}
{props.placeholder || props.label}
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

Using || here will fall back to props.label when props.placeholder is an empty string; consider using the nullish coalescing operator (??) to only fall back on null or undefined.

Suggested change
{props.placeholder || props.label}
{props.placeholder ?? props.label}

Copilot uses AI. Check for mistakes.

@@ -229,7 +229,9 @@ export default function DBSelect(props: DBSelectProps) {
}
aria-describedby={props.ariaDescribedBy ?? state._descByIds}>
{/* Empty option for floating label */}
<option hidden></option>
<Show when={props.variant === 'floating' || props.placeholder}>
<option class="placeholder" value=""></option>
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

The placeholder <option> has no visible text; screen readers may announce it as blank. Add inner text or an aria-label matching the placeholder so users understand its purpose.

Suggested change
<option class="placeholder" value=""></option>
<option class="placeholder" value="">{props.placeholder}</option>

Copilot uses AI. Check for mistakes.

@@ -9,7 +9,7 @@
<div class="db-select">
<label for="test1">Label</label>
<select id="test1" aria-describedby="db-infotext-01">
<option hidden></option>
<option class="placeholder" value=""></option>
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

The example’s placeholder option is empty and lacks accessible text. Include placeholder text or an aria-label so it's announced properly in the dropdown.

Suggested change
<option class="placeholder" value=""></option>
<option class="placeholder" value="">Select an option</option>

Copilot uses AI. Check for mistakes.

@@ -18,7 +18,7 @@
<div class="db-select">
<label for="test2">Label</label>
<select id="test2" aria-describedby="db-infotext-02">
<option hidden></option>
<option class="placeholder" value=""></option>
Copy link
Preview

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

This second example also uses an empty placeholder <option>; please add visible or ARIA text to ensure it’s clear when navigating the list.

Suggested change
<option class="placeholder" value=""></option>
<option class="placeholder" value="">Select an option</option>

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working 🧱components Changes inside components folder 🍄🆙improvement New feature or request
Projects
Status: 🏗 In development
Development

Successfully merging this pull request may close these issues.

DBSelect dropdown checkmark on first element
1 participant