Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♿ a11y(accordion): accordion not accessible #1450

Merged
merged 5 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-pets-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/ds-core': patch
---

**accordion**: make it keyboard accessible
5 changes: 5 additions & 0 deletions .changeset/six-readers-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/ds-core': patch
---

**list**: make accordion accessible to the keyboard
3 changes: 0 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
"angular": "npx nx run create-angular",
"angular:start": "npx nx run start-angular"
},
"nx": {
"includedScripts": []
},
"private": true,
"workspaces": [
"packages/*",
"libs/*",
"docs",
"e2e"
],
"nx": {
"includedScripts": []
},
"devDependencies": {
"@angular-devkit/build-angular": "~15.0.0",
"@angular-devkit/core": "~15.0.0",
Expand Down Expand Up @@ -140,10 +140,5 @@
"vue": "~3.4.15",
"vue-tsc": "~1.8.8",
"zone.js": "~0.11.4"
},
"executors": "./executors.json",
"dependencies": {
"@nx/devkit": "18.0.5"
},
"packageManager": "pnpm@8.5.0+sha1.83c41fe4ebdb61e08446f8bb68a75fb48756b330"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

.bal-accordion__summary
position: static
display: block
&--trigger
cursor: pointer
&:focus-visible
@extend %focus-shadow
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BEM } from '../../../utils/bem'
import { Loggable, Logger, LogInstance } from '../../../utils/log'
import { stopEventBubbling } from '../../../utils/form-input'
import { AccordionState } from '../../../interfaces'
import { isEnterKey, isSpaceKey } from '@baloise/web-app-utils'

@Component({
tag: 'bal-accordion-summary',
Expand Down Expand Up @@ -91,6 +92,13 @@ export class AccordionSummary implements ComponentInterface, Loggable {
this.parentAccordionElement?.humanToggle()
}

private onKeyDown = (ev: KeyboardEvent) => {
if (isEnterKey(ev) || isSpaceKey(ev)) {
stopEventBubbling(ev)
this.parentAccordionElement?.humanToggle()
}
}

/**
* RENDER
* ------------------------------------------------------
Expand All @@ -109,9 +117,11 @@ export class AccordionSummary implements ComponentInterface, Loggable {
attributes = {
'aria-controls': `${this.parentAccordionId}-details-content`,
'role': 'button',
'tabindex': 0,
'part': buttonPart,
'data-testid': 'bal-accordion-button',
'onClick': this.onClick,
'onKeyDown': this.onKeyDown,
}
}

Expand All @@ -121,6 +131,8 @@ export class AccordionSummary implements ComponentInterface, Loggable {
class={{
...block.class(),
...block.modifier('trigger').class(this.trigger),
...block.modifier('inner-trigger').class(!this.trigger),
'bal-focused': this.trigger,
}}
{...attributes}
data-testid="bal-accordion-summary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.bal-accordion__trigger
position: static
display: block
&__button
display: flex
justify-content: center
Expand All @@ -12,3 +13,6 @@
width: 3rem
user-select: none
cursor: pointer

.bal-accordion__trigger__button.bal-focused:focus-visible
@extend %focus-shadow
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export class AccordionTrigger implements ComponentInterface, Loggable {
return this.el?.closest('bal-accordion') || null
}

private get parentAccordionSummaryElement(): HTMLBalAccordionSummaryElement | null {
return this.el?.closest('bal-accordion-summary') || null
}

/**
* PRIVATE METHODS
* ------------------------------------------------------
Expand Down Expand Up @@ -133,6 +137,16 @@ export class AccordionTrigger implements ComponentInterface, Loggable {
const expanded = this.state === AccordionState.Expanded || this.state === AccordionState.Expanding
const buttonPart = expanded ? 'button expanded' : 'button'

const parentSummaryEl = this.parentAccordionSummaryElement
let triggerAttributes = {
tabindex: -1,
}
if (parentSummaryEl && !parentSummaryEl.trigger) {
triggerAttributes = {
tabindex: 0,
}
}

return (
<Host
id={id}
Expand All @@ -159,13 +173,15 @@ export class AccordionTrigger implements ComponentInterface, Loggable {
<button
class={{
...block.element('button').class(),
'bal-focused': parentSummaryEl && !parentSummaryEl.trigger,
}}
id={`${id}-button`}
aria-controls={`${this.parentAccordionId}-details-content`}
aria-label="accordion trigger"
part={buttonPart}
data-testid="bal-accordion-trigger"
onClick={this.onClick}
{...triggerAttributes}
>
<bal-icon turn={turn} name={icon}></bal-icon>
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, Host, h, Element, EventEmitter, Event, Prop, Watch, ComponentInterface } from '@stencil/core'
import { Loggable, Logger, LogInstance } from '../../../utils/log'
import { isEnterKey, isSpaceKey } from '@baloise/web-app-utils'

@Component({
tag: 'bal-list-item-accordion-head',
Expand Down Expand Up @@ -54,6 +55,12 @@ export class ListItemAccordionHead implements ComponentInterface, Loggable {
}
}

private onKeyDown = (ev: KeyboardEvent) => {
if (isSpaceKey(ev) || isEnterKey(ev)) {
this.onClick()
}
}

/**
* RENDER
* ------------------------------------------------------
Expand All @@ -67,7 +74,10 @@ export class ListItemAccordionHead implements ComponentInterface, Loggable {
'bal-list__item__accordion-head': true,
'bal-list__item__accordion-head--open': this.accordionOpen,
}}
role="button"
tabindex="0"
onClick={this.onClick}
onKeyDown={this.onKeyDown}
>
<slot></slot>
<bal-list-item-icon right>
Expand Down