[BUG] BitDropdownItem missing role="button" on enabled action-only items
- Langage dominant
- HTML
- Étoiles
- 10
- Forks
- 4
- Merge moyen
- 4 j
- PR mergées (30 j)
- 1
Description
### 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`.
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.
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.