Skip to content

Commit

Permalink
feat(checkbox): Add keyboard handling for Enter and Space keys to tog…
Browse files Browse the repository at this point in the history
…gle checked state
  • Loading branch information
mryunt02 committed Oct 18, 2024
1 parent 7f66431 commit 3a22ca0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/checkbox-group/checkbox/bl-checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ export default class BlCheckbox extends FormControlMixin(LitElement) {
private handleFieldValueChange = (event: CustomEvent<Array<string>>) => {
this.checked = event.detail.includes(this.value);
};
private handleKeyDown(event: KeyboardEvent) {
if (event.code === "Enter" || event.code === "Space") {
this.checked = !this.checked;
this.onChange(this.checked);
event.preventDefault();
}
}

render(): TemplateResult {
let icon = "";
Expand Down Expand Up @@ -206,6 +213,7 @@ export default class BlCheckbox extends FormControlMixin(LitElement) {
aria-readonly=${this.disabled}
.indeterminate=${this.indeterminate}
@change=${this.handleChange}
@keydown=${this.handleKeyDown}
value=${ifDefined(this.value)}
@blur=${this.blur}
/>
Expand Down

0 comments on commit 3a22ca0

Please sign in to comment.