albx / albx/bitblazor

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

Abierto
#105 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug components
Lenguaje dominante
HTML
Estrellas
10
Forks
4
Merge medio
4 d
PR fusionados (30 d)
1

Descripción

### 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 `` element with no `href` attribute and no explicit `role`.

Per the HTML-AAM / ARIA mapping, an `` 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 `` instead of an ``. 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 ``" 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()`:

```csharp
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 `
` 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 `
` 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 (#95), which renders `BitDropdownItem` instances without `Href` for page-size selection.
- Do not convert `BitDropdownItem` to a native `
` 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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.