From 508a76e0e1d23326f776d4d3d8727152d8063e56 Mon Sep 17 00:00:00 2001 From: Chris Daley Date: Wed, 23 Oct 2024 22:56:58 -0700 Subject: [PATCH] Add keyboard navigation per issue #182 --- src/components/bc-balance.ts | 5 ++ src/components/bc-button.ts | 3 + src/components/bc-currency-switcher.ts | 25 +++++++ src/components/bc-modal-header.ts | 26 +++++++ src/components/bc-modal.ts | 16 +++- src/components/bc-navbar.ts | 23 +++++- src/components/bc-pay-button.ts | 11 ++- src/components/bc-router-outlet.ts | 4 +- src/components/bc-start.ts | 25 +++++-- src/components/connectors/ConnectorElement.ts | 14 ++++ src/components/flows/bc-connect.ts | 23 +++++- src/components/flows/bc-payment.ts | 30 +++++++- src/components/internal/InternalElement.ts | 12 ++- src/components/internal/bci-button.ts | 21 ++++++ src/components/internal/bci-connecting.ts | 6 ++ src/components/pages/bc-help.ts | 4 +- src/components/pages/bc-lnbits.ts | 11 ++- src/components/pages/bc-lnfi.ts | 5 +- src/components/pages/bc-send-payment.ts | 73 ++++++++++++++----- 19 files changed, 295 insertions(+), 42 deletions(-) diff --git a/src/components/bc-balance.ts b/src/components/bc-balance.ts index 568282f..e483e13 100644 --- a/src/components/bc-balance.ts +++ b/src/components/bc-balance.ts @@ -49,6 +49,9 @@ export class Balance extends withTwind()(BitcoinConnectElement) { class="font-medium font-sans mr-2 flex justify-center items-center gap-0.5 ${classes[ 'text-brand-mixed' ]}" + role="status" + aria-live="${this._loading ? 'polite' : 'off'}" + aria-busy="${this._loading ? 'true' : 'false'}" > ${this._balance || 'Loading...'} `; @@ -109,6 +112,8 @@ export class Balance extends withTwind()(BitcoinConnectElement) { this._balance = '⚠️'; // FIXME: better error handling console.error(error); + } finally { + this._loading = false; } })(); } diff --git a/src/components/bc-button.ts b/src/components/bc-button.ts index 6c654e3..c9e3e6f 100644 --- a/src/components/bc-button.ts +++ b/src/components/bc-button.ts @@ -42,6 +42,9 @@ export class Button extends withTwind()(BitcoinConnectElement) {
@@ -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)} > ${currency.flag}
store.getState().pushRoute('/help')} + @keydown=${this._handleKeydownHelp} > ${helpIcon}
` @@ -39,7 +45,11 @@ export class ModalHeader extends withTwind()(BitcoinConnectElement) { ${this.closable ? html`
${crossIcon}
` @@ -54,6 +64,22 @@ export class ModalHeader extends withTwind()(BitcoinConnectElement) { private _handleClose() { this.dispatchEvent(new Event('onclose', {bubbles: true, composed: true})); } + + // Handle keyboard interactions for the close button + private _handleKeydownClose(event: KeyboardEvent) { + if (event.key === 'Enter' || event.key === ' ') { + event.preventDefault(); + this._handleClose(); + } + } + + // Handle keyboard interactions for the help button + private _handleKeydownHelp(event: KeyboardEvent) { + if (event.key === 'Enter' || event.key === ' ') { + event.preventDefault(); + store.getState().pushRoute('/help'); + } + } } declare global { diff --git a/src/components/bc-modal.ts b/src/components/bc-modal.ts index 2b08287..64c9b61 100644 --- a/src/components/bc-modal.ts +++ b/src/components/bc-modal.ts @@ -11,18 +11,26 @@ import {closeModal} from '../api'; @customElement('bc-modal') export class Modal extends withTwind()(BitcoinConnectElement) { override render() { - return html`