Skip to content

Commit

Permalink
fix: Ensure checkbox label is always clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
KeithClinard committed Aug 26, 2024
1 parent c97b4be commit 6a003b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/design-system/src/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ select.form-select,
}
}
}

.form-check-label {
user-select: none;
}
10 changes: 8 additions & 2 deletions packages/ember/src/components/form/checkbox.gts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class FormCheckbox extends BoundValue<
CheckboxSignature,
boolean
> {
internalId = crypto.randomUUID();

get classList() {
const classes = ['form-check-input'];

Expand Down Expand Up @@ -54,6 +56,10 @@ export default class FormCheckbox extends BoundValue<
return this.args.type === 'switch';
}

get id() {
return this.args.id || this.internalId;
}

@action
change(evt: Event) {
const target = evt.target as HTMLInputElement;
Expand All @@ -67,14 +73,14 @@ export default class FormCheckbox extends BoundValue<
checked={{this.value}}
class={{this.classList}}
disabled={{@disabled}}
id={{@id}}
id={{this.id}}
role={{if this.isSwitch "switch" "checkbox"}}
type="checkbox"
value={{this.value}}
{{on "change" this.change}}
...attributes
/>
<label class="form-check-label" for={{@id}}>
<label class="form-check-label" for={{this.id}}>
{{@label}}
</label>
</div>
Expand Down

0 comments on commit 6a003b3

Please sign in to comment.