Skip to content

luci-base: fix label association warning for Dropdown widget#8382

Open
stangri wants to merge 1 commit intoopenwrt:masterfrom
stangri:fix/dropdown-label-association
Open

luci-base: fix label association warning for Dropdown widget#8382
stangri wants to merge 1 commit intoopenwrt:masterfrom
stangri:fix/dropdown-label-association

Conversation

@stangri
Copy link
Member

@stangri stangri commented Mar 4, 2026

Summary

  • Add data-widget-id attribute to the Dropdown widget's container <div>, matching the pattern already used by Checkbox (ui.js line 647)
  • This allows renderFrame()'s existing fallback selector (form.js line 4454) to find the widget, resolving browser console accessibility warnings

Problem

The Dropdown widget renders as a <div>, which is not a labelable HTML element. When used with MultiValue or other dropdown-based form options, renderFrame() creates a <label for="widget.cbid..."> but no element with that id or data-widget-id exists in the Dropdown output.

This causes browser DevTools to report:

  • "A <label> element with a for attribute doesn't match any element id"

Fix

Single-line addition — add data-widget-id to UIDropdown.render():

'data-widget-id': this.options.id ? `widget.${this.options.id}` : null,

This leverages the existing fallback mechanism in renderFrame():

const elem = node.nextElementSibling.querySelector(`#${node.getAttribute('for')}`)
    ?? node.nextElementSibling.querySelector(`[data-widget-id="${node.getAttribute('for')}"]`);

Test plan

  • Open any LuCI page using MultiValue widget (e.g., any app with a multi-select dropdown)
  • Check browser DevTools console — label association warning should no longer appear
  • Verify clicking the label text still focuses/opens the dropdown

🤖 Generated with Claude Code

The Dropdown widget renders as a <div>, which is not a labelable HTML
element. When used with MultiValue or other dropdown-based form options,
the browser console shows "label's for attribute doesn't match any
element id" because renderFrame() creates a <label for="widget.cbid...">
but no element with that id or data-widget-id exists in the Dropdown.

Add data-widget-id attribute to the Dropdown container, matching the
pattern already used by Checkbox (ui.js line 647). This allows
renderFrame()'s existing fallback selector (form.js line 4454) to find
the widget element, resolving the browser accessibility warning.

Signed-off-by: Stan Grishin <stangri@melmac.ca>
@stangri stangri requested review from hnyman and systemcrash March 4, 2026 01:57
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Warning

Some formality checks failed.

Consider (re)reading submissions guidelines.

Failed checks

Issues marked with an ❌ are failing checks.

Commit 9c347df

  • 🔶 Commit subject length: recommended max 50, required max 60 characters

For more details, see the full job log.

Something broken? Consider providing feedback.

@systemcrash
Copy link
Contributor

A bit of a can of worms here. I can only reproduce this on Chrome which generates those notices, and I cannot seem to silence the notice with this change alone. The checkboxes which use 'label' for the text label (also) generate the notice.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants