Skip to content

[BUG] BitDropdownItem missing role="button" on enabled action-only items #105

Description

@albx

Describe the bug

BitDropdownItem only sets role="button" (and aria-disabled="true") when Disabled is true. When an item is used as a pure action (no Href, only OnClick) and is enabled, it renders as an <a> element with no href attribute and no explicit role.

Per the HTML-AAM / ARIA mapping, an <a> without an href attribute has no implicit ARIA role (it maps to role=generic), even though the element is still made focusable via an explicit tabindex="0". As a result, assistive technology has no reliable way to announce the item as an interactive control (button/link) — this is a WCAG 4.1.2 (Name, Role, Value) violation for enabled, action-only dropdown items.

This was discovered while reviewing whether BitDropdownItem should render as a <button> instead of an <a>. Switching the element type is not advisable (Bootstrap Italia's CSS uses tag-qualified selectors like a.dropdown-item / a.list-item, and the rest of the library — BitPageItem, BitToolbarItem, BitBottomNavItem — follows the same "always <a>" convention). The actual fix should be scoped to correcting the missing role for the enabled, no-Href case, but this needs further investigation to confirm the right approach and check for the same pattern elsewhere in the library.

Relevant code: BitDropdownItem.razor.cs, method SetDisabled():

private void SetDisabled()
{
    if (Disabled)
    {
        AdditionalAttributes["aria-disabled"] = "true";
        AdditionalAttributes["role"] = "button";
    }
    else
    {
        AdditionalAttributes.Remove("aria-disabled");
        AdditionalAttributes.Remove("role");
    }
}

To Reproduce

Steps to reproduce the behavior:

  1. Render a BitDropdown with a BitDropdownItem that has no Href set and only an OnClick callback (e.g. the page-size changer items in BitPagination's ShowChanger feature).
  2. Inspect the rendered HTML of the enabled item.
  3. Observe the <a> element has no href and no role attribute.
  4. Inspect the same item with a screen reader (e.g. NVDA) — it is not announced as a button or link, only as plain focusable text.

Expected behavior

Enabled, action-only BitDropdownItem instances (no Href, OnClick set) should always expose role="button" regardless of the Disabled state, so assistive technology can correctly announce the control's role. Items with a real Href should keep native <a> link semantics (no explicit role needed).

Screenshots

N/A

Desktop (please complete the following information):

  • OS: N/A (applies to all)
  • Browser: N/A (applies to all)
  • Version: N/A

Additional context

  • This needs investigation before implementing a fix. Confirm whether the same missing-role gap exists on other Href-optional item components (BitPageItem, BitToolbarItem, BitBottomNavItem), and whether the fix should be a shared helper rather than a one-off change in BitDropdownItem.
  • Related to the BitPagination ShowChanger feature ([FEATURE] Pagination - Add Changer section (records per page dropdown) #95), which renders BitDropdownItem instances without Href for page-size selection.
  • Do not convert BitDropdownItem to a native <button> element — Bootstrap Italia's CSS relies on tag-qualified selectors (a.dropdown-item, a.list-item), and the rest of the library follows the same anchor-based convention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcomponentsIssues related to the components

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions