Skip to content

Commit

Permalink
fix(checkbox): avoid 'undefined' values and fallback to an empty string
Browse files Browse the repository at this point in the history
fix(radio): avoid 'undefined' values and fallback to an empty string

docs: pass down name attribute to the elements
  • Loading branch information
daenub authored Jul 24, 2024
1 parent 820deca commit 2f9f95f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class LeuCheckbox extends LeuElement {
@input=${this.handleInput}
.checked=${this.checked}
?disabled=${this.disabled}
.value=${this.value}
.value=${this.value ?? ""}
/>
<label for=${`checkbox-${this.name}`} class="label"><slot></slot></label>
<leu-icon class="icon" name="check"></leu-icon>
Expand Down
9 changes: 7 additions & 2 deletions src/components/checkbox/stories/checkbox.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ export default {
},
}

function Template({ label = "Label", value, checked, disabled }) {
function Template({ label = "Label", value, checked, disabled, name = "" }) {
return html`
<leu-checkbox .value=${value} ?checked=${checked} ?disabled=${disabled}>
<leu-checkbox
.value=${value}
?checked=${checked}
?disabled=${disabled}
name=${name}
>
${label}
</leu-checkbox>
`
Expand Down
2 changes: 1 addition & 1 deletion src/components/radio/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class LeuRadio extends LeuElement {
@input=${this.handleInput}
.checked=${this.checked}
?disabled=${this.disabled}
.value=${this.value}
.value=${this.value ?? ""}
/>
<label for=${`radio-${this.name}`} class="label"><slot></slot></label>
`
Expand Down
8 changes: 7 additions & 1 deletion src/components/radio/stories/radio.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ function Template({
value = "",
checked = false,
disabled = false,
name = "",
}) {
return html`
<leu-radio .value=${value} ?checked=${checked} ?disabled=${disabled}>
<leu-radio
.value=${value}
?checked=${checked}
?disabled=${disabled}
name=${name}
>
${label}
</leu-radio>
`
Expand Down

0 comments on commit 2f9f95f

Please sign in to comment.