Skip to content

Commit 304db40

Browse files
authored
Merge pull request #170 from betocantu93/toggle-buttons
docs: toggle buttons docs
2 parents ec82342 + 96ada0a commit 304db40

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

packages/core/docs/navigation/button/demo/d09-toggle-buttons.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,49 @@ order: 9
44

55
# Toggle buttons
66

7+
<EuiText>
8+
<p>You can create a toggle button with any button type like the standard <strong>EuiButton</strong>, <strong>EuiButtonEmpty</strong>, or <strong>EuiButtonIcon</strong>. Use state management to handle the visual differences for on and off. Though there are two <strong>exclusive</strong> situations to consider.</p>
9+
<ol>
10+
<li>If your button changes its readable <strong>text</strong>, via children or <EuiCode>aria-label</EuiCode>, then there is no additional accessibility concern.</li>
11+
<li>If your button only changes the <strong>visual</strong> appearance, you must add <EuiCode>aria-pressed</EuiCode> passing a boolean for the on and off states. All EUI button types provide a helper prop for this called <EuiCode>isSelected</EuiCode>.</li>
12+
</ol>
13+
14+
</EuiText>
715

816
```hbs template
9-
<TodoText/>
10-
```
17+
{{#let
18+
(use-state false)
19+
(use-state false)
20+
(use-state true)
21+
(use-state false)
22+
as |toggle0 toggle1 toggle2 toggle3|
23+
}}
24+
<EuiButton {{on 'click' (fn toggle0.setState (not toggle0.value))}}>
25+
{{if toggle0.value 'Hey there good lookin' 'Toggle me'}}
26+
</EuiButton>
27+
<EuiButtonIcon
28+
@iconType={{if toggle1.value 'play' 'pause'}}
29+
title={{if toggle1.value 'Play' 'Pause'}}
30+
aria-label={{if toggle1.value 'Play' 'Pause'}}
31+
{{on 'click' (fn toggle1.setState (not toggle1.value))}}
32+
/>
33+
<EuiButton
34+
@isSelected={{toggle2.value}}
35+
@fill={{toggle2.value}}
36+
@iconType={{if toggle2.value 'starFilledSpace' 'starPlusEmpty'}}
37+
{{on 'click' (fn toggle2.setState (not toggle2.value))}}
38+
>
39+
Toggle me
40+
</EuiButton>
41+
<EuiButtonIcon
42+
@display={{if toggle3.value 'base' 'empty'}}
43+
@size='m'
44+
aria-label='Autosave'
45+
title='Autosave'
46+
@iconType='save'
47+
aria-pressed={{toggle3.value}}
48+
@color={{toggle3.value 'primary' 'text'}}
49+
{{on 'click' (fn toggle3.setState (not toggle3.value))}}
50+
/>
51+
{{/let}}
52+
```

0 commit comments

Comments
 (0)