eslint-plugin-lit icon indicating copy to clipboard operation
eslint-plugin-lit copied to clipboard

Consider exception to `no-attribute-value` if type is checkbox/radio

Open WickyNilliams opened this issue 2 years ago • 0 comments

Checkboxes and radios are unique in that they have a default value of "on". If you use property binding, you cannot take advantage of this:

html`<input type="radio" name="test" .value=${undefined} />` // will submit as string "undefined"
html`<input type="radio" name="test" .value=${null} />` // will submit as empty string ""
html`<input type="radio" name="test" .value=${""} />` // will submit as empty string ""

Whereas if you use the attribute binding, you can conditionally render the attribute and fallback to the default:

html`<input type="radio" name="test" value=${ifDefined(value)} />` // will submit as "on"

In my testing this works correctly even if a value is initially set, and later changed, or if attribute is later removed.

Happy to attempt a PR if you don't object

WickyNilliams avatar Jan 27 '22 17:01 WickyNilliams