43081j / eslint-plugin-lit

lit-html support for ESLint
116 stars 21 forks source link

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

Open WickyNilliams opened 2 years ago

WickyNilliams commented 2 years ago

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