Skip to content

Commit

Permalink
feat(navbar): add a11y label and clickable logo
Browse files Browse the repository at this point in the history
  • Loading branch information
hirsch88 committed Jan 24, 2025
1 parent 1e1b805 commit 83fc8b7
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-rats-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/ds-core': minor
---

**navbar**: add a11y label for logo and make it clickable
17 changes: 17 additions & 0 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,7 @@ export namespace Components {
* Defines if the logo animation should be active
*/
"animated": boolean;
"configChanged": (state: BalConfigState) => Promise<void>;
/**
* Link of the logo / title.
*/
Expand All @@ -2030,6 +2031,14 @@ export namespace Components {
* Src to display a logo -> replaces the default Baloise Logo
*/
"logo"?: string;
/**
* If `true` the logo is rendered as a button
*/
"logoClickable": boolean;
/**
* Defines the label of the logo
*/
"logoLabel"?: string;
/**
* Size of the logo SVG
*/
Expand Down Expand Up @@ -7178,6 +7187,14 @@ declare namespace LocalJSX {
* Src to display a logo -> replaces the default Baloise Logo
*/
"logo"?: string;
/**
* If `true` the logo is rendered as a button
*/
"logoClickable"?: boolean;
/**
* Defines the label of the logo
*/
"logoLabel"?: string;
/**
* Size of the logo SVG
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { I18n } from '../../../interfaces'

export interface I18nBalNavbarBrand {
logoButtonLabel: string
}

export const i18nBalNavbarBrand: I18n<I18nBalNavbarBrand> = {
en: {
logoButtonLabel: 'To Homepage',
},
fr: {
logoButtonLabel: 'Vers la page d’accueil',
},
it: {
logoButtonLabel: 'Alla pagina principale',
},
nl: {
logoButtonLabel: 'Naar de startpagina',
},
es: {
logoButtonLabel: 'A la página principal',
},
pt: {
logoButtonLabel: 'Para a página inicial',
},
sv: {
logoButtonLabel: 'Till startsidan',
},
fi: {
logoButtonLabel: 'Etusivulle',
},
de: {
logoButtonLabel: 'Zur Startseite',
},
pl: {
logoButtonLabel: 'Na stronę główną',
},
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Component, Element, h, Host, Prop, State, Event, EventEmitter } from '@stencil/core'
import { Component, Element, h, Host, Prop, State, Event, EventEmitter, Method } from '@stencil/core'
import { BEM } from '../../../utils/bem'
import { BalScrollHandler } from '../../../utils/scroll'
import { balBrowser } from '../../../utils/browser'
import { wait, waitAfterFramePaint, waitForRequestIdleCallback } from '../../../utils/helpers'
import { wait } from '../../../utils/helpers'
import { i18nBalNavbarBrand } from './bal-navbar-brand.i18n'
import { BalConfigState, BalLanguage, defaultConfig, ListenToConfig } from '../../../utils/config'

@Component({
tag: 'bal-navbar-brand',
Expand All @@ -12,13 +14,24 @@ export class NavbarBrand {

@Element() el!: HTMLElement

@State() language: BalLanguage = defaultConfig.language
@State() isMenuActive = false

/**
* Link of the logo / title.
*/
@Prop() href?: string = ''

/**
* If `true` the logo is rendered as a button
*/
@Prop() logoClickable = false

/**
* Defines the label of the logo
*/
@Prop() logoLabel?: string

/**
* Specifies where to display the linked URL.
* Only applies when an `href` is provided.
Expand Down Expand Up @@ -83,6 +96,15 @@ export class NavbarBrand {
this.bodyScrollHandler.disconnect()
}

/**
* @internal define config for the component
*/
@Method()
@ListenToConfig()
async configChanged(state: BalConfigState): Promise<void> {
this.language = state.language
}

async resetIsMenuActive(ev: MediaQueryListEvent) {
if (ev.matches && !this.simple) {
this.toggle(false)
Expand Down Expand Up @@ -131,6 +153,8 @@ export class NavbarBrand {
<bal-logo animated={this.animated} color={'white'} size={this.logoSize}></bal-logo>
)

const logoLabel = this.logoLabel ? this.logoLabel : i18nBalNavbarBrand[this.language].logoButtonLabel

return (
<Host
class={{
Expand All @@ -139,9 +163,19 @@ export class NavbarBrand {
}}
>
{this.href ? (
<a href={this.href} target={this.target} onClick={(ev: MouseEvent) => this.balNavigate.emit(ev)}>
<a
aria-label={logoLabel}
title={logoLabel}
href={this.href}
target={this.target}
onClick={(ev: MouseEvent) => this.balNavigate.emit(ev)}
>
{logoTemplate}
</a>
) : this.logoClickable ? (
<button aria-label={logoLabel} title={logoLabel} onClick={(ev: MouseEvent) => this.balNavigate.emit(ev)}>
{logoTemplate}
</button>
) : (
logoTemplate
)}
Expand Down

0 comments on commit 83fc8b7

Please sign in to comment.