mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
fix(checkbox): support two way binding
- Forward events, inline functions - Add style, remove exported props (#7)
This commit is contained in:
parent
6cc2eecd88
commit
724196abb5
4 changed files with 21 additions and 21 deletions
|
@ -4,13 +4,13 @@
|
|||
export let checked = false;
|
||||
export let indeterminate = false;
|
||||
export let disabled = false;
|
||||
export let id = undefined;
|
||||
export let id = Math.random();
|
||||
export let labelText = undefined;
|
||||
export let hideLabel = false;
|
||||
export let title = '';
|
||||
export let wrapperClassName = undefined;
|
||||
export { wrapperClassName as wrapperClass };
|
||||
export let props = {};
|
||||
export let style = undefined;
|
||||
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { cx } from '../../lib';
|
||||
|
@ -20,17 +20,26 @@
|
|||
const _innerLabelClass = cx('--checkbox-label-text', hideLabel && '--visually-hidden');
|
||||
const _wrapperClass = cx('--form-item', '--checkbox-wrapper', wrapperClassName);
|
||||
|
||||
function handleChange(event) {
|
||||
dispatch('change', { checked: event.target.checked, id, event });
|
||||
let inputRef = undefined;
|
||||
|
||||
$: {
|
||||
dispatch('check', { id, checked });
|
||||
|
||||
if (inputRef) {
|
||||
inputRef.checked = checked;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class={_wrapperClass}>
|
||||
<div on:click on:mouseover on:mouseenter on:mouseleave class={_wrapperClass} {style}>
|
||||
<input
|
||||
{...props}
|
||||
bind:this={inputRef}
|
||||
type="checkbox"
|
||||
class={cx('--checkbox')}
|
||||
on:change={handleChange}
|
||||
on:change
|
||||
on:change={() => {
|
||||
checked = !checked;
|
||||
}}
|
||||
{indeterminate}
|
||||
{disabled}
|
||||
{checked}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue