Skip to content

Commit

Permalink
Accessibilty additions
Browse files Browse the repository at this point in the history
  • Loading branch information
chebizarro committed Oct 30, 2024
1 parent 6dfa7ab commit 6b59ea6
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
39 changes: 38 additions & 1 deletion src/components/bc-currency-switcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ export class CurrencySwitcher extends withTwind()(BitcoinConnectElement) {

override render() {
if (!this._isSwitchingCurrency) {
return html`<div class="flex justify-center items-center gap-2">
return html`<div class="flex justify-center items-center gap-2">
<div
class="${classes.interactive}"
role="button"
tabindex="0"
aria-label="Open currency selection"
@click=${this._showSelectVisibility}
@keydown=${this._handleKeydown}
>
<slot></slot>
</div>
Expand All @@ -81,7 +85,12 @@ export class CurrencySwitcher extends withTwind()(BitcoinConnectElement) {
class="${selectedCurrency === currency.value
? 'bg-blue-500 text-white'
: ''} flex items-center justify-center py-2 px-4 hover:text-white hover:bg-blue-500 rounded-lg hover:border-blue-500 cursor-pointer"
role="option"
aria-selected="${selectedCurrency === currency.value}"
tabindex="0"
@click=${() => this._selectCurrency(currency.value)}
@keydown=${(event: KeyboardEvent) =>
this._handleCurrencyKeydown(event, currency.value)}
>
<span class="text-orange-400 inline-block mr-2 text-xl"
>${currency.flag}</span
Expand All @@ -94,11 +103,39 @@ export class CurrencySwitcher extends withTwind()(BitcoinConnectElement) {

private _showSelectVisibility() {
this._isSwitchingCurrency = true;
// Focus the first currency option when switching is enabled
setTimeout(() => {
const firstCurrencyOption = this.shadowRoot?.querySelector(
'[role="option"]'
) as HTMLElement;
firstCurrencyOption?.focus();
}, 0);
}

private _selectCurrency(selectedCurrency: string) {
store.getState().setCurrency(selectedCurrency);
this._isSwitchingCurrency = false;
// Ensure focus returns to the triggering button
const triggerButton = this.shadowRoot?.querySelector(
'[role="button"]'
) as HTMLElement;
triggerButton?.focus();
}

// Handle keydown events for currency selection
private _handleCurrencyKeydown(event: KeyboardEvent, currency: string) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
this._selectCurrency(currency);
}
}

// Handle keydown events for opening the currency list
public override _handleKeydown(event: KeyboardEvent) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
this._showSelectVisibility();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/components/bc-pay-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class PayButton extends withTwind()(BitcoinConnectElement) {
});
this._setPaid = setPaid;
}

}

declare global {
Expand Down
4 changes: 3 additions & 1 deletion src/components/bc-router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {routes} from './routes';
export class RouterOutlet extends withTwind()(BitcoinConnectElement) {
override render() {
//TODO: r = routes[this._route](this._routeParams);
return html`<div class="flex flex-col w-full">${routes[this._route]}</div>`;
return html`<div class="flex flex-col w-full" aria-live="polite">
${routes[this._route]}
</div>`;
}
}

Expand Down
24 changes: 18 additions & 6 deletions src/components/bc-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ export class Start extends withTwind()(BitcoinConnectElement) {
override render() {
return html`<div
class="flex flex-col justify-center items-center w-full font-sans"
aria-live="polite"
role="region"
aria-label="${this._connected
? 'Connected Wallet Section'
: 'Connect Wallet Section'}"
>
${this._connected
? html`
${this._showBalance
? html`<span
? html` <span
class="text-xs font-medium mb-2 ${classes[
'text-neutral-secondary'
]}"
Expand All @@ -46,7 +51,7 @@ export class Start extends withTwind()(BitcoinConnectElement) {
<bc-currency-switcher>
<bc-balance class="text-2xl"></bc-balance>
</bc-currency-switcher>`
: html` <span
: html`<span
class="text-lg font-medium mt-4 -mb-4 ${classes[
'text-neutral-secondary'
]}"
Expand All @@ -59,21 +64,28 @@ export class Start extends withTwind()(BitcoinConnectElement) {
class="my-8 ${classes[
'text-neutral-primary'
]} w-64 max-w-full text-center"
role="heading"
aria-level="1"
>
How would you like to
connect${this._appName ? `\nto ${this._appName}` : ''}?
</h1>
<bc-connector-list></bc-connector-list>
<div class="flex flex-col items-center w-full font-sans text-sm">
<h1 class="mt-8 ${classes['text-neutral-primary']} text-center">
<h1
class="mt-8 ${classes['text-neutral-primary']} text-center"
role="heading"
aria-level="2"
>
Don't have a bitcoin lightning wallet?
<a
class="no-underline font-bold ${classes.interactive} ${classes[
'text-brand-mixed'
]} "
]}"
@click=${() => store.getState().pushRoute('/new-wallet')}
role="link"
tabindex="0"
aria-label="Get a bitcoin lightning wallet"
>Get one here</a
>
</h1>
Expand Down

0 comments on commit 6b59ea6

Please sign in to comment.