Skip to content

Commit 25cca95

Browse files
docs: explain how to make disabled buttons accessible (#4077)
Co-authored-by: Russell J.T. Dyer <6652767+russelljtdyer@users.noreply.github.com>
1 parent 3f2dc6a commit 25cca95

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed

articles/components/button/index.adoc

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
tab-title: Usage
33
layout: tabbed-page
44
title: Button
5-
page-title: Button component | Vaadin components
6-
description: The Button component allows users to perform actions. It comes in several different style variants and supports icons as well as text labels.
7-
meta-description: The Vaadin component Button allows users to perform actions. It comes in several different style variants and supports icons as well as text labels.
5+
page-title: Button Component | Vaadin Components
6+
description: The Button component allows users to perform actions. It comes in several different style variants and supports icons, as well as text labels.
7+
meta-description: The Vaadin component Button allows users to perform actions. It comes in several different style variants and supports icons, as well as text labels.
88
page-links:
99
- 'API: https://cdn.vaadin.com/vaadin-web-components/{moduleNpmVersion:@vaadin/button}/#/elements/vaadin-button[TypeScript] / https://vaadin.com/api/platform/{moduleMavenVersion:com.vaadin:vaadin}/com/vaadin/flow/component/button/Button.html[Java]'
1010
- 'Source: https://github.com/vaadin/web-components/tree/v{moduleNpmVersion:@vaadin/button}/packages/button[TypeScript] / https://github.com/vaadin/flow-components/tree/{moduleMavenVersion:com.vaadin:vaadin}/vaadin-button-flow-parent[Java]'
@@ -120,6 +120,7 @@ endif::[]
120120

121121
Primary danger buttons should only be used when a dangerous action is the most likely action. An example of this would be the affirmative *Delete* action in a deletion confirmation dialog. Secondary and Tertiary variants can be used for actions related to current errors, such as resolving them or viewing their details.
122122

123+
123124
[role="since:com.vaadin:vaadin@V24.5"]
124125
=== Warning Variant
125126

@@ -150,6 +151,7 @@ include::{root}/frontend/demo/component/button/react/button-warning.tsx[render,t
150151
endif::[]
151152
--
152153

154+
153155
=== Size Variants
154156

155157
The following size variants are available for Button instances whose size needs to be different from the default:
@@ -291,7 +293,6 @@ The *Tertiary + Contrast* combination should be avoided because of similarity to
291293
The standard Button colors can be adjusted using <<{articles}/styling/lumo/lumo-style-properties/color#,the Lumo color properties>>. Therefore, these variants shouldn't be used to replace standard buttons only to achieve a different color.
292294

293295

294-
295296
== Buttons with Icons
296297

297298
Buttons can have icons instead of text, or they can have icons along with text.
@@ -332,7 +333,6 @@ Additionally, [since:com.vaadin:vaadin@V23.3]##<<../tooltip#,tooltips>>## can be
332333
Use the `icon` / `LUMO_ICON` theme variant on icon-only buttons to reduce the white space on either side of the icon. The Flow `Button` component automatically applies the `icon` variant if the icon is the only child of the component.
333334

334335

335-
336336
== Buttons with Images
337337

338338
Images on buttons can be used like icons. See the icon usage recommendations for more information.
@@ -365,7 +365,7 @@ endif::[]
365365

366366
== Disabled
367367

368-
Buttons representing actions that aren't currently available to the user should be either hidden or disabled. A disabled button is rendered as "dimmed", and is excluded from the focus order. This may be useful when you don't want interactive UI elements to receive the focus using the tab key.
368+
Buttons representing actions that aren't currently available to the user should be either hidden or disabled. A disabled button is rendered as "dimmed".
369369

370370
[.example]
371371
--
@@ -393,14 +393,33 @@ endif::[]
393393
--
394394

395395

396-
=== Hidden vs. Disabled
396+
=== Focus & Hover
397397

398-
Hiding entirely an unavailable action is often preferable to a disabled button, as this reduces UI clutter. However, in certain situations, this can be problematic. If the user expects a button to be present -- such as at the end of a form -- hiding the button can cause confusion, even if the form clearly shows the presence of one or more invalid fields. Also, since a hidden button doesn't occupy any space in the UI, toggling its visibility can cause unwanted changes in the layout of other elements.
398+
By default, disabled buttons are not focusable and cannot react to hover events. This can cause accessibility issues by making them entirely invisible to assistive technologies, and prevents the use of Tooltips to explain why the action is not available. This can be addressed by enabling the feature flag `accessibleDisabledButtons`, which allows you to focus and hover on disabled buttons, while preventing them from being triggered:
399399

400+
[.example]
401+
--
402+
.`Flow`
403+
[source,properties]
404+
----
405+
# Add this line to src/main/resources/vaadin-featureflags.properties
406+
com.vaadin.experimental.accessibleDisabledButtons=true
407+
----
400408

401-
=== Show Error on Click
409+
.`Lit & React`
410+
[source,js]
411+
----
412+
// Set before any button is added to the DOM
413+
window.Vaadin.featureFlags.accessibleDisabledButtons = true;
414+
----
415+
--
416+
417+
418+
=== Alternatives to Disabling
402419

403-
As an alternative to hiding or disabling buttons, configure instead unavailable actions to show an error message when the button is clicked by using a <<../notification/index#,Notification>> or an adjacent inline text element. This approach is the most accessible option, but may be frustrating to users who expect unavailable actions to be distinguished somehow from available actions.
420+
The most obvious alternative to disabling a button is to hide it. This reduces UI clutter, but can cause confusion since the user won't know where to watch for the button once the action it represents becomes available. There's also a risk of undesired layout shifts in the UI when the button appears.
421+
422+
Another option is to keep the button visible and enabled, but show an error, e.g. using a Notification, when it's clicked. This option is best combined with some custom styling of the button to give the user a hint that the action is unavailable.
404423

405424

406425
=== Prevent Multiple Clicks
@@ -433,7 +452,6 @@ endif::[]
433452
--
434453

435454

436-
437455
== Focus
438456

439457
As with other components, the focus ring is only rendered when the button is focused by keyboard or programmatically.
@@ -456,6 +474,7 @@ include::{root}/frontend/demo/component/button/react/button-focus.tsx[render,tag
456474
endif::[]
457475
--
458476

477+
459478
=== Auto Focus
460479

461480
Buttons can receive keyboard focus automatically when the UI in which they appear is rendered.
@@ -544,6 +563,7 @@ include::{root}/frontend/demo/component/button/react/button-labels.tsx[render,ta
544563
endif::[]
545564
--
546565

566+
547567
=== Buttons in Forms
548568

549569
Buttons in forms should be placed below the form with which they're associated. They should be aligned left, with the primary action first, followed by other actions, in order of importance.

articles/components/menu-bar/index.adoc

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
tab-title: Usage
33
layout: tabbed-page
44
title: Menu Bar
5-
page-title: Menu Bar component | Vaadin components
5+
page-title: Menu Bar Component | Vaadin Components
66
description: Menu Bar is a horizontal button bar with hierarchical drop-down menus.
7-
meta-description: Learn how to implement the Vaadin Menu Bar component in your Vaadin applications and how you can customize it for a better user experience.
7+
meta-description: Learn how to implement the Vaadin Menu Bar component in Vaadin applications and how you can customize it for a better user experience.
88
page-links:
99
- 'API: https://cdn.vaadin.com/vaadin-web-components/{moduleNpmVersion:@vaadin/menu-bar}/#/elements/vaadin-menu-bar[TypeScript] / https://vaadin.com/api/platform/{moduleMavenVersion:com.vaadin:vaadin}/com/vaadin/flow/component/menubar/MenuBar.html[Java]'
1010
- 'Source: https://github.com/vaadin/web-components/tree/v{moduleNpmVersion:@vaadin/menu-bar}/packages/menu-bar[TypeScript] / https://github.com/vaadin/flow-components/tree/{moduleMavenVersion:com.vaadin:vaadin}/vaadin-menu-bar-flow-parent[Java]'
@@ -160,6 +160,7 @@ endif::[]
160160
[NOTE]
161161
In versions prior to 24.3, theme names must be used instead of class names (`theme` property / `addThemeNames` Java method). The CSS syntax for targeting a theme name is `[theme~="custom-theme"]`
162162

163+
163164
[role="since:com.vaadin:vaadin@V24.5"]
164165
=== Drop-down Indicators
165166

@@ -254,7 +255,6 @@ include::{root}/src/main/java/com/vaadin/demo/component/menubar/MenuBarIcons.jav
254255
----
255256
endif::[]
256257

257-
258258
ifdef::react[]
259259
[source,tsx]
260260
----
@@ -331,6 +331,25 @@ include::{root}/frontend/demo/component/menubar/react/menu-bar-disabled.tsx[rend
331331
endif::[]
332332
--
333333

334+
By default, disabled buttons (i.e., root-level items) are not focusable and cannot react to hover events. This can cause accessibility issues by making them entirely invisible to assistive technologies, and prevents the use of Tooltips to explain why the action is not available. This can be addressed by enabling the feature flag `accessibleDisabledButtons`, which allows focusing and hovering on disabled buttons, while preventing them from being triggered:
335+
336+
[.example]
337+
--
338+
.`Flow`
339+
[source,properties]
340+
----
341+
# Add this line to src/main/resources/vaadin-featureflags.properties
342+
com.vaadin.experimental.accessibleDisabledButtons=true
343+
----
344+
345+
.`Lit & React`
346+
[source,js]
347+
----
348+
// Set before any button is added to the DOM
349+
window.Vaadin.featureFlags.accessibleDisabledButtons = true;
350+
----
351+
--
352+
334353

335354
=== Checkable Menu Items
336355

0 commit comments

Comments
 (0)