Skip to content

Commit ce550f1

Browse files
committed
fix: icon button pressed state wasn't setting aria attrs without toggle
1 parent 66f4c7e commit ce550f1

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

MIGRATING.md

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ There are [newly updated instructiong](INSTALL.md#integration-for-sapper) for us
3737
- Open state is now controled by an `open` prop, instead of `open` and `close` functions. There are also `isOpen` and `setOpen` functions.
3838
- Lists should now be placed below `Content` element, rather than being the `Content` component. For selection from a list, use the new `selection` prop on the dialog.
3939
- Slider dialogs are styled a bit differently. See the [demo](https://sveltematerialui.com/demo/dialog/).
40+
- Icon Button
41+
- No longer emit 'MDCIconButtonToggle:change' event without the `toggle` prop. Instead, listen for click event.
4042
- Linear Progress
4143
- Removed `reversed` prop.
4244
- List

packages/icon-button/IconButton.svelte

+8-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class={classMap({
2121
[className]: true,
2222
'mdc-icon-button': true,
23-
'mdc-icon-button--on': pressed,
23+
'mdc-icon-button--on': pressed !== uninitializedValue && pressed,
2424
'mdc-card__action': context === 'card:action',
2525
'mdc-card__action--icon': context === 'card:action',
2626
'mdc-top-app-bar__navigation-icon': context === 'top-app-bar:navigation',
@@ -35,7 +35,11 @@
3535
.map(([name, value]) => `${name}: ${value};`)
3636
.concat([style])
3737
.join(' ')}
38-
aria-pressed={toggle ? (pressed ? 'true' : 'false') : null}
38+
aria-pressed={pressed !== uninitializedValue
39+
? pressed
40+
? 'true'
41+
: 'false'
42+
: null}
3943
aria-label={pressed ? ariaLabelOn : ariaLabelOff}
4044
data-aria-label-on={ariaLabelOn}
4145
data-aria-label-off={ariaLabelOff}
@@ -64,6 +68,7 @@
6468
import Button from '@smui/common/Button.svelte';
6569
6670
const forwardEvents = forwardEventsBuilder(get_current_component());
71+
let uninitializedValue = () => {};
6772
6873
export let use = [];
6974
let className = '';
@@ -72,7 +77,7 @@
7277
export let ripple = true;
7378
export let color = null;
7479
export let toggle = false;
75-
export let pressed = false;
80+
export let pressed = uninitializedValue;
7681
export let ariaLabelOn = null;
7782
export let ariaLabelOff = null;
7883
export let href = null;

site/src/routes/demo/icon-button/_Toggle.svelte

+8-12
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,23 @@
99
<Icon class="material-icons" on>alarm_on</Icon>
1010
<Icon class="material-icons">alarm_off</Icon>
1111
</IconButton>
12-
<div>
13-
<Button on:click={() => (initialOn = !initialOn)}>
14-
<Label>Toggle Programmatically</Label>
15-
</Button>
16-
&nbsp;(Note: this doesn't fire the&nbsp;
17-
<code>MDCIconButtonToggle:change</code> &nbsp;event.)
18-
</div>
12+
13+
<!-- Note: this doesn't fire the MDCIconButtonToggle:change event. -->
14+
<Button on:click={() => (initialOn = !initialOn)}>
15+
<Label>Toggle Programmatically</Label>
16+
</Button>
1917
</div>
2018
<div style="display: flex; align-items: center;">
19+
<!-- Note: don't use `toggle` prop in this case. -->
2120
<IconButton
2221
on:click={() => toggleClicked++}
23-
on:MDCIconButtonToggle:change={() => (usingEvents = !usingEvents)}
22+
on:click={() => (usingEvents = !usingEvents)}
2423
pressed={usingEvents}
2524
>
2625
<Icon class="material-icons" on>bookmark</Icon>
2726
<Icon class="material-icons">bookmark_border</Icon>
2827
</IconButton>
29-
<div>
30-
Using events instead of bound variables. (Note: don't use&nbsp;
31-
<code>toggle</code> &nbsp;prop in this case.)
32-
</div>
28+
<div>Using events instead of bound variables.</div>
3329
</div>
3430

3531
<pre class="status">Clicked: {toggleClicked}</pre>

0 commit comments

Comments
 (0)