Add keyboard support to onboarding links (#17816)

This commit is contained in:
Paul Bottein 2023-09-04 17:20:51 +02:00 committed by GitHub
parent 5d5894cae6
commit 5e1583f925
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -17,6 +17,8 @@ class OnboardingWelcomeLink extends LitElement {
@property() public iconPath!: string;
@property({ attribute: true, type: Boolean }) public noninteractive?: boolean;
@queryAsync("mwc-ripple") private _ripple!: Promise<Ripple | null>;
@state() private _shouldRenderRipple = false;
@ -24,6 +26,7 @@ class OnboardingWelcomeLink extends LitElement {
protected render(): TemplateResult {
return html`
<ha-card
.tabIndex=${this.noninteractive ? "-1" : "0"}
@focus=${this.handleRippleFocus}
@blur=${this.handleRippleBlur}
@mousedown=${this.handleRippleActivate}
@ -33,6 +36,7 @@ class OnboardingWelcomeLink extends LitElement {
@touchstart=${this.handleRippleActivate}
@touchend=${this.handleRippleDeactivate}
@touchcancel=${this.handleRippleDeactivate}
@keydown=${this._handleKeyDown}
>
<ha-svg-icon .path=${this.iconPath}></ha-svg-icon>
${this.label}
@ -41,6 +45,12 @@ class OnboardingWelcomeLink extends LitElement {
`;
}
private _handleKeyDown(ev: KeyboardEvent): void {
if (ev.key === "Enter" || ev.key === " ") {
(ev.target as HTMLElement).click();
}
}
private _rippleHandlers: RippleHandlers = new RippleHandlers(() => {
this._shouldRenderRipple = true;
return this._ripple;

View File

@ -21,6 +21,7 @@ class OnboardingWelcomeLinks extends LitElement {
href="https://www.home-assistant.io/blog/2016/01/19/perfect-home-automation/"
>
<onboarding-welcome-link
noninteractive
.iconPath=${mdiFileDocument}
.label=${this.localize("ui.panel.page-onboarding.welcome.vision")}
>