Skip to content

Commit f41165d

Browse files
authored
add more information to button.md (#4169)
1 parent d5d51a7 commit f41165d

1 file changed

Lines changed: 64 additions & 18 deletions

File tree

  • apps/design-system-docs/docs/components/inputs

apps/design-system-docs/docs/components/inputs/button.md

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Button
22

3-
_Buttons_ allow users to take action with a single click or tap.
3+
_Buttons_ are the primary action triggers in EDS. They support direct actions (e.g., submit, confirm) and toggle selections, with variants to indicate hierarchy (contained, outlined, ghost) and intent (primary, secondary, danger). Always pair buttons with clear, action-oriented labels.
44

55
<iframe
66
class="sb-iframe"
@@ -18,51 +18,89 @@ _Buttons_ allow users to take action with a single click or tap.
1818

1919
Use a button for a direct, immediate user action (submit, confirm, start, cancel, toggle) rather than for pure navigation or passive information.
2020

21+
Use a button for **direct, immediate actions** (e.g., submit, confirm, cancel) or **toggle selections** (e.g., switching views). Avoid buttons for:
22+
2123
## Structure
2224

23-
- Contained
24-
- Contained with icon
25-
- Outlined
26-
- Ghost
27-
- Ghost with icon
25+
All variants support:
26+
27+
- **Left/right icons** (paired with text).
28+
- **Icon-only** (requires an `aria-label` for accessibility).
29+
- **Text-only** (default).
30+
31+
**Toggle Buttons**
32+
33+
Group related actions in a **shared container** where only one option can be ctive at a time. Use for:
34+
35+
- Switching views (e.g., "List" vs "Grid").
36+
- Mutually exclusive options (e.g., "Day" vs "Week" in a calendar).
37+
38+
**Density**
39+
40+
- **Default**: Standard padding and typography.
41+
- **Compact**: Reduced padding for dense UIs (e.g., toolbars). **Must** provide a way to switch to default mode for accessibility [1].
2842

2943
## Hierarchy
3044

31-
### Buttons
45+
Use variants to guide users to the most important action:
46+
| Variant | Emphasis | Use Case |
47+
|-----------|----------|-----------------------------------|
48+
| Contained | High | Primary actions (e.g., "Submit") |
49+
| Outlined | Medium | Secondary actions (e.g., "Cancel") |
50+
| Ghost | Low | Tertiary actions (e.g., toolbar icons) |
3251

33-
Use variants to differentiate the hierarchy.
52+
Communicate action criticality with color:
3453

35-
- Contained - being high-emphasis
36-
- Outlined - being medium-emphasis
37-
- Ghost - being low-emphasis
54+
- **Primary**: Default (e.g., "Save").
55+
- **Secondary**: Less prominent (e.g., "Save as draft").
56+
- **Danger**: Destructive actions (e.g., "Delete"). **Danger buttons must invert the order in button groups** (e.g., ["Cancel" (primary), "Delete" (danger)]) to prevent accidental activation.
3857

3958
![buttons](../assets/buttons.jpeg)
4059

41-
#### Guidelines
42-
43-
There are `primary`, `secondary` and `danger` colour buttons available in the `contained`, `outlined` and `ghost` variations. All variations can have the following: an icon on the left, an icon on the right, an icon with no text and text only with no icon. When using an icon, it must be directly related to the action and label of the button.
60+
All variations can have the following: an icon on the left, an icon on the right, an icon with no text and text only with no icon. When using an icon, it must be directly related to the action and label of the button.
4461

4562
#### Accessibility
4663

4764
The `aria-disabled` attribute makes it possible to semantically disable the `Button` without hiding it from assistive technologies, such as screen readers. In EDS, the `Button` will be visually styled as disabled, but it is up to the developer to actually disable the button.
4865

66+
**Standard Buttons**
67+
68+
- **Keyboard**: Supports `Tab` focus; activates with `Enter` or `Space`.
69+
- **Disabled State**:
70+
- Use `aria-disabled="true"` to **semantically disable** the button (visible to screen readers).
71+
- **Developers must** prevent clicks via `onClick` logic (EDS styles the button visually but does not block interactions).
72+
73+
**Icon-Only Buttons**
74+
75+
- **Always** provide an accessible name:
76+
```html
77+
<Button aria-label="save report"
78+
<Icon data={save}></Icon>
79+
</Button
80+
```
81+
- Avoid unless space is **severely constrained** (e.g., toolbars).
82+
4983
### Toggle buttons
5084

51-
`Toggle buttons` allow users to select one of multiple options with a single click or tap.
85+
`Toggle buttons` allow users to select one of multiple options with a single click or tap. Only one option in a group of toggle buttons can be active at a time. Selecting one option deselects any other.  
5286

5387
#### Guidelines
5488

5589
EDS has one set of primary toggle buttons with either an icon and no text, or text and no icon. When using an icon it must be directly related to the action of the button.
5690

57-
Toggle buttons group a set of related actions in one shared common container. Only one option in a group of toggle buttons can be selected and active at a time. Selecting one option deselects any other. 
91+
- Ensure **only one option is selectable** at a time.
92+
- **Label the group** for screen readers using `aria-label` or `aria-labelledby`.
5893

5994
#### Accessibility
6095

61-
Button.Toggle sets `aria-pressed="bool"` according to the button state. You should provide an accessible label with `aria-label="label"`, `aria-labelledby="id"` or `<label>`.
96+
Toggle sets `aria-pressed="bool"` according to the button state. You should provide an accessible label with `aria-label="label"`, `aria-labelledby="id"` or `<label>`.
97+
98+
- **Group Labeling**: Use `aria-label` or `aria-labelledby` to describe the group’s purpose (e.g., "View options").
99+
- **State**: `aria-pressed="true/false"` reflects the toggle state.
62100

63101
#### Compact
64102

65-
Compact mode is toggled using EdsProvider.
103+
Compact mode is toggled using `EdsProvider`.
66104

67105
:::note
68106
The compact mode should come with the possibility to switch to normal mode for accessibility reasons.
@@ -85,6 +123,10 @@ The compact mode should come with the possibility to switch to normal mode for a
85123

86124
✅ You can use an icon to help clarify an action. Always use icons that clearly communicate their intended purpose
87125

126+
✅ Provide accessible names for icon-only buttons (`aria-label`).
127+
128+
✅ **Allow switching from compact to default mode** for accessibility.
129+
88130
❌ Do not apply the same colour to all the buttons in a group. Use variants (contained, outlined, ghost) to differentiate the hierarchy instead
89131

90132
❌ Do not use the same variant for all action buttons since the user needs to understand which call to action has the most emphasis
@@ -94,3 +136,7 @@ The compact mode should come with the possibility to switch to normal mode for a
94136
❌ Do not assign the same order to danger buttons as the “positive” action button groups (primary + secondary), use the opposite (secondary + primary) instead
95137

96138
❌ Do not use an icon that can mislead the main action
139+
140+
❌ Do not rely on color alone to convey meaning (ensure text/icons are clear).
141+
142+
❌ Do not disable buttons without explanation (e.g., add a tooltip for "Why is this disabled?").

0 commit comments

Comments
 (0)