@@ -46,15 +46,16 @@ export interface FormAssociated {
4646 disabled : boolean ;
4747
4848 /**
49- * Gets the current form value of a component.
49+ * Gets the current form value of a component. Defaults to the component's
50+ * `value` attribute.
5051 *
5152 * @return The current form value.
5253 */
5354 [ getFormValue ] ( ) : FormValue | null ;
5455
5556 /**
5657 * Gets the current form state of a component. Defaults to the component's
57- * `[formValue]` .
58+ * `[getFormValue]()` result .
5859 *
5960 * Use this when the state of an element is different from its value, such as
6061 * checkboxes (internal boolean state and a user string value).
@@ -72,25 +73,26 @@ export interface FormAssociated {
7273 formDisabledCallback ( disabled : boolean ) : void ;
7374
7475 /**
75- * A callback for when the form requests to reset its value. Typically, the
76- * default value that is reset is represented in the attribute of an element.
76+ * An optional callback for when the form requests to reset its value.
77+ * Typically, the default value that is reset is represented in the attribute
78+ * of an element.
7779 *
7880 * This means the attribute used for the value should not update as the value
7981 * changes. For example, a checkbox should not change its default `checked`
8082 * attribute when selected. Ensure form values do not reflect.
8183 */
82- formResetCallback ( ) : void ;
84+ formResetCallback ? ( ) : void ;
8385
8486 /**
85- * A callback for when the form restores the state of a component. For
86- * example, when a page is reloaded or forms are autofilled.
87+ * An optional callback for when the form restores the state of a component.
88+ * For example, when a page is reloaded or forms are autofilled.
8789 *
8890 * @param state The state to restore, or null to reset the form control's
8991 * value.
9092 * @param reason The reason state was restored, either `'restore'` or
9193 * `'autocomplete'`.
9294 */
93- formStateRestoreCallback (
95+ formStateRestoreCallback ? (
9496 state : FormRestoreState | null ,
9597 reason : FormRestoreReason ,
9698 ) : void ;
@@ -238,7 +240,9 @@ export function mixinFormAssociated<
238240 return this . hasAttribute ( 'disabled' ) ;
239241 }
240242 set disabled ( disabled : boolean ) {
241- this . toggleAttribute ( 'disabled' , disabled ) ;
243+ // Coerce `disabled` in `Boolean()` to ensure that setting to `null` or
244+ // `undefined` sets the attribute to `false`.
245+ this . toggleAttribute ( 'disabled' , Boolean ( disabled ) ) ;
242246 // We don't need to call `requestUpdate()` since it's called synchronously
243247 // in `attributeChangedCallback()`.
244248 }
@@ -282,9 +286,7 @@ export function mixinFormAssociated<
282286 }
283287
284288 [ getFormValue ] ( ) : FormValue | null {
285- // Closure does not allow abstract symbol members, so a default
286- // implementation is needed.
287- throw new Error ( 'Implement [getFormValue]' ) ;
289+ return this . getAttribute ( 'value' ) ;
288290 }
289291
290292 [ getFormState ] ( ) : FormValue | null {
@@ -294,13 +296,6 @@ export function mixinFormAssociated<
294296 formDisabledCallback ( disabled : boolean ) {
295297 this . disabled = disabled ;
296298 }
297-
298- abstract formResetCallback ( ) : void ;
299-
300- abstract formStateRestoreCallback (
301- state : FormRestoreState | null ,
302- reason : FormRestoreReason ,
303- ) : void ;
304299 }
305300
306301 return FormAssociatedElement ;
0 commit comments