From 08f9b8aa4d22404a29dee48622c95247b5475ebb Mon Sep 17 00:00:00 2001 From: Arthurk12 Date: Tue, 17 Nov 2026 14:37:15 -0300 Subject: [PATCH] fix(BBButton): keep a disabled button with a tooltip focusable A disabled BBButton gets the native `disabled` attribute and `pointer-events: none`, so its tooltip never opens on hover and the button leaves the tab order: the reason it is disabled never reaches mouse, keyboard or screen-reader users. Consumers wrap the button and put a tooltip on the wrapper, which fixes hover only. When `disabled` and `tooltipLabel` are both set, render `aria-disabled="true"` instead of the native attribute, as BBBCheckbox and BBBToggle do: - clicks, Enter and Space are cancelled with `preventDefault()` and `onClick` is not called, so a `type="submit"` button doesn't submit its form; - the disabled look comes from `:disabled` and `[aria-disabled='true']` rather than a styling prop, so both states share it; hover and active styles apply only to an enabled button, and only a natively disabled one drops pointer events, so the tooltip opens on hover and the not-allowed cursor shows; - the stacked helper icon ignores clicks and shows no hover. The tooltip opens on `focusin` as well as hover, because in the stacked layout its reference is the wrapper, which focus never lands on. Its text is kept in a `hidden` span the button's `aria-describedby` points to, since Tippy only mounts its content while shown; this also describes stacked buttons, which Tippy's own aria-describedby never reached. A wrapper inside BBButton carrying the tooltip was discarded: a natively disabled button still can't take focus, leaving the keyboard gap. Without a tooltip, a disabled button stays natively disabled. --- src/components/Button/README.md | 16 +++++- src/components/Button/component.stories.tsx | 14 ++++- src/components/Button/component.tsx | 49 ++++++++++++---- src/components/Button/styles.ts | 64 +++++++++++---------- src/components/Button/type.ts | 3 +- 5 files changed, 99 insertions(+), 47 deletions(-) diff --git a/src/components/Button/README.md b/src/components/Button/README.md index 674953b..8af1dd1 100644 --- a/src/components/Button/README.md +++ b/src/components/Button/README.md @@ -63,6 +63,18 @@ import { BBButton } from 'bbb-ui-components-react'; ``` +### Disabled Button with Tooltip + +Useful to explain why a button is disabled. The tooltip shows on hover and keyboard focus, and its text is also exposed to screen readers as the button's description. + +A disabled button with a `tooltipLabel` stays in the tab order so keyboard users can reach the tooltip: it gets `aria-disabled="true"` instead of the native `disabled` attribute, keeps the disabled look, and ignores clicks, Enter and Space, without submitting its form when `type="submit"`. Without a `tooltipLabel`, a disabled button is natively disabled. + +```jsx +import { BBButton } from 'bbb-ui-components-react'; + + (console.log('clicked'))}/> +``` + ### Full-width Button ```jsx @@ -111,7 +123,7 @@ const FooterButton = styled(BBButton)` | `id` | `string` | `''` | The unique identifier for the button. | | `dataTest` | `string` | | The 'data-test' attribute for testing purposes. | | `label` | `string` | | The text to be displayed on the button. | -| `tooltipLabel` | `string` | | The text to be displayed in a tooltip on hover. | +| `tooltipLabel` | `string` | | Text shown in a tooltip on hover and keyboard focus. When set, a disabled button stays focusable (`aria-disabled`) so the tooltip can be reached. | | `tooltipPlacement` | `keyof typeof TOOLTIP_PLACEMENTS` | `'top'` | The placement of the tooltip. | | `onClick` | `() => void` | | The function to be called when the button is clicked. | | `onKeyDown` | `(event: React.KeyboardEvent) => void` | | The function to be called when a key is pressed. | @@ -123,7 +135,7 @@ const FooterButton = styled(BBButton)` | `size` | `keyof typeof SIZES` | `'medium'` | The size of the button. | | `layout` | `keyof typeof LAYOUTS` | `'default'` | The layout of the button. | | `type` | `'button' \| 'submit' \| 'reset'` | `'button'` | The native `type` attribute of the `