mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
refactor(toggle): access ref in afterUpdate method
This commit is contained in:
parent
2cac297abf
commit
8ea50a807a
2 changed files with 8 additions and 14 deletions
|
@ -9,20 +9,17 @@
|
|||
export let labelB = 'On';
|
||||
export let style = undefined;
|
||||
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { createEventDispatcher, afterUpdate } from 'svelte';
|
||||
import { cx } from '../../lib';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
let inputRef = undefined;
|
||||
|
||||
$: {
|
||||
dispatch('toggle', { id, toggled });
|
||||
|
||||
if (inputRef) {
|
||||
afterUpdate(() => {
|
||||
inputRef.checked = toggled;
|
||||
}
|
||||
}
|
||||
dispatch('toggle', { id, toggled });
|
||||
});
|
||||
</script>
|
||||
|
||||
<div on:click on:mouseover on:mouseenter on:mouseleave class={cx('--form-item', className)} {style}>
|
||||
|
|
|
@ -9,20 +9,17 @@
|
|||
export let labelB = 'On';
|
||||
export let style = undefined;
|
||||
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { createEventDispatcher, afterUpdate } from 'svelte';
|
||||
import { cx } from '../../lib';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
let inputRef = undefined;
|
||||
|
||||
$: {
|
||||
dispatch('toggle', { id, toggled });
|
||||
|
||||
if (inputRef) {
|
||||
afterUpdate(() => {
|
||||
inputRef.checked = toggled;
|
||||
}
|
||||
}
|
||||
dispatch('toggle', { id, toggled });
|
||||
});
|
||||
</script>
|
||||
|
||||
<div on:click on:mouseover on:mouseenter on:mouseleave class={cx('--form-item', className)} {style}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue