|
42 | 42 | bind:checked={nativeChecked}
|
43 | 43 | data-indeterminate={!isUninitializedValue(indeterminate) && indeterminate
|
44 | 44 | ? 'true'
|
45 |
| - : null} |
| 45 | + : undefined} |
46 | 46 | on:blur
|
47 | 47 | on:focus
|
48 | 48 | {...nativeControlAttrs}
|
|
92 | 92 | export let touch = false;
|
93 | 93 | export let indeterminate: UninitializedValue | boolean = uninitializedValue;
|
94 | 94 | export let group: UninitializedValue | any[] = uninitializedValue;
|
95 |
| - export let checked: UninitializedValue | boolean = uninitializedValue; |
| 95 | + export let checked: UninitializedValue | boolean | null = uninitializedValue; |
96 | 96 | export let value: any = null;
|
97 | 97 | export let valueKey: UninitializedValue | string = uninitializedValue;
|
98 | 98 | export let input$use: ActionArray = [];
|
|
107 | 107 | let rippleActive = false;
|
108 | 108 | let inputProps =
|
109 | 109 | getContext<{ id?: string } | undefined>('SMUI:generic:input:props') ?? {};
|
110 |
| - let nativeChecked = isUninitializedValue(group) |
| 110 | + let nativeChecked: boolean | undefined = isUninitializedValue(group) |
111 | 111 | ? isUninitializedValue(checked)
|
112 | 112 | ? false
|
113 |
| - : checked |
| 113 | + : checked ?? undefined |
114 | 114 | : group.indexOf(value) !== -1;
|
115 | 115 | let context = getContext<string | undefined>('SMUI:checkbox:context');
|
116 | 116 | let dataTableHeader = getContext<boolean | undefined>(
|
|
160 | 160 |
|
161 | 161 | // Now check individual state.
|
162 | 162 | if (isUninitializedValue(checked)) {
|
163 |
| - if (previousNativeChecked !== nativeChecked) { |
| 163 | + if (!!previousNativeChecked !== !!nativeChecked) { |
164 | 164 | // The checkbox was clicked by the user.
|
165 | 165 | callHandleChange = true;
|
166 | 166 | }
|
167 |
| - } else if (checked !== nativeChecked) { |
| 167 | + } else if (checked !== (nativeChecked ?? null)) { |
168 | 168 | if (checked === previousChecked) {
|
169 | 169 | // The checkbox was clicked by the user
|
170 | 170 | // and the change needs to flow up.
|
171 |
| - checked = nativeChecked; |
| 171 | + checked = nativeChecked ?? null; |
| 172 | + if (!isUninitializedValue(indeterminate)) { |
| 173 | + indeterminate = false; |
| 174 | + } |
172 | 175 | } else {
|
173 | 176 | // The checkbox was changed programmatically
|
174 | 177 | // and the change needs to flow down.
|
175 |
| - nativeChecked = checked; |
| 178 | + nativeChecked = checked ?? undefined; |
176 | 179 | }
|
177 | 180 | callHandleChange = true;
|
178 | 181 | }
|
|
205 | 208 | }
|
206 | 209 |
|
207 | 210 | onMount(() => {
|
| 211 | + checkbox.indeterminate = |
| 212 | + !isUninitializedValue(indeterminate) && indeterminate; |
| 213 | +
|
208 | 214 | instance = new MDCCheckboxFoundation({
|
209 | 215 | addClass,
|
210 | 216 | forceLayout: () => element.offsetWidth,
|
211 | 217 | hasNativeControl: () => true,
|
212 | 218 | isAttachedToDOM: () => Boolean(element.parentNode),
|
213 |
| - isChecked: () => nativeChecked, |
| 219 | + isChecked: () => nativeChecked ?? false, |
214 | 220 | isIndeterminate: () =>
|
215 | 221 | isUninitializedValue(indeterminate) ? false : indeterminate,
|
216 | 222 | removeClass,
|
|
225 | 231 | return getElement();
|
226 | 232 | },
|
227 | 233 | get checked() {
|
228 |
| - return nativeChecked; |
| 234 | + return nativeChecked ?? false; |
229 | 235 | },
|
230 | 236 | set checked(value) {
|
231 | 237 | if (nativeChecked !== value) {
|
|
0 commit comments