Skip to content

Commit 943795f

Browse files
committed
feat: migrate switch to new mdc-web version
1 parent 58b98e0 commit 943795f

File tree

8 files changed

+176
-145
lines changed

8 files changed

+176
-145
lines changed

MIGRATING.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ This doc contains information that will help you migrate your code from an older
77
SMUI 6 migrated to upstream MDC 13.0 from 11.0:
88
https://github.com/material-components/material-components-web/blob/master/CHANGELOG.md#1300-2021-09-24
99

10+
## Changes
11+
12+
### Components
13+
14+
- Switch
15+
- No longer needs `valueKey` prop.
16+
- Default color is now "primary".
17+
1018
# SMUI 4 -> SMUI 5
1119

1220
## Breaking Changes
@@ -45,7 +53,7 @@ You should update your MDC dependencies to 11.0 as well.
4553

4654
## New Features
4755

48-
### Compoennts
56+
### Components
4957

5058
- Banner
5159
- Add focus trap on the banner.

packages/ripple/Ripple.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type RippleProps = {
1313
color?: 'primary' | 'secondary';
1414
/** Whether the ripple is active. Leave null to determine automatically. */
1515
active?: boolean;
16+
rippleElement?: HTMLElement;
1617
eventTarget?: HTMLElement;
1718
activeTarget?: HTMLElement;
1819
addClass?: (className: string) => void;
@@ -30,6 +31,7 @@ export default function Ripple(
3031
disabled = false,
3132
color,
3233
active,
34+
rippleElement,
3335
eventTarget,
3436
activeTarget,
3537
addClass = (className) => node.classList.add(className),
@@ -77,7 +79,8 @@ export default function Ripple(
7779
instance = new MDCRippleFoundation({
7880
addClass,
7981
browserSupportsCssVars: () => util.supportsCssVariables(window),
80-
computeBoundingRect: () => node.getBoundingClientRect(),
82+
computeBoundingRect: () =>
83+
(rippleElement || node).getBoundingClientRect(),
8184
containsEventTarget: (target) => node.contains(target as Node),
8285
deregisterDocumentInteractionHandler: (evtType, handler) =>
8386
document.documentElement.removeEventListener(
@@ -177,6 +180,7 @@ export default function Ripple(
177180
disabled,
178181
color,
179182
active,
183+
rippleElement,
180184
eventTarget,
181185
activeTarget,
182186
addClass,
@@ -190,6 +194,7 @@ export default function Ripple(
190194
disabled: false,
191195
color: undefined,
192196
active: undefined,
197+
rippleElement: undefined,
193198
eventTarget: undefined,
194199
activeTarget: undefined,
195200
addClass: (className) => node.classList.add(className),

packages/site/src/routes/demo/switch/_PrimaryColor.svelte renamed to packages/site/src/routes/demo/switch/_SecondaryColor.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div>
22
<FormField>
3-
<Switch color="primary" bind:checked={checked1} />
3+
<Switch color="secondary" bind:checked={checked1} />
44
<span slot="label">Fields of grain.</span>
55
</FormField>
66
</div>
@@ -9,7 +9,7 @@
99

1010
<div style="margin-top: 1em;">
1111
<FormField align="end">
12-
<Switch color="primary" bind:checked={checked2} />
12+
<Switch color="secondary" bind:checked={checked2} />
1313
<span slot="label">Fields of grain.</span>
1414
</FormField>
1515
</div>

packages/site/src/routes/demo/switch/index.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
<Demo component={Simple} file="switch/_Simple.svelte" />
1111

12-
<Demo component={PrimaryColor} file="switch/_PrimaryColor.svelte">
13-
Primary color
12+
<Demo component={SecondaryColor} file="switch/_SecondaryColor.svelte">
13+
Secondary color
1414
</Demo>
1515

1616
<Demo component={Group} file="switch/_Group.svelte">Group switch</Demo>
@@ -20,6 +20,6 @@
2020
import Demo from '$lib/Demo.svelte';
2121
2222
import Simple from './_Simple.svelte';
23-
import PrimaryColor from './_PrimaryColor.svelte';
23+
import SecondaryColor from './_SecondaryColor.svelte';
2424
import Group from './_Group.svelte';
2525
</script>

0 commit comments

Comments
 (0)