Skip to content

Commit

Permalink
fix: fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB committed Nov 28, 2024
1 parent 1b5013e commit b188112
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/elements/core/base-elements/link-base-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ abstract class SbbLinkBaseElement extends SbbActionBaseElement {

/** Default render method for link-like components. Can be overridden if the LinkRenderVariables are not needed. */
protected override render(): TemplateResult {
return this.renderLink(() => this.renderTemplate());
return this.renderLink(this.renderTemplate());
}

protected renderLink(renderContent?: () => TemplateResult): TemplateResult {
protected renderLink(renderContent: TemplateResult): TemplateResult {
return html`
<a
class="sbb-action-base ${this.localName}"
Expand All @@ -88,7 +88,7 @@ abstract class SbbLinkBaseElement extends SbbActionBaseElement {
tabindex=${this.maybeDisabled && !this.maybeDisabledInteractive ? '-1' : nothing}
aria-disabled=${this.maybeDisabled ? 'true' : nothing}
>
${renderContent ? renderContent() : nothing}
${renderContent}
${!!this.href && this.target === '_blank'
? html`<sbb-screen-reader-only
>. ${i18nTargetOpensInNewWindow[this.language.current]}</sbb-screen-reader-only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,31 @@ snapshots["sbb-teaser-product renders DOM"] =
/* end snapshot sbb-teaser-product renders DOM */

snapshots["sbb-teaser-product renders Shadow DOM"] =
`<a
class="sbb-action-base sbb-teaser-product"
href="https://www.sbb.ch"
>
<span class="sbb-teaser-product__image-container">
<slot name="image">
</slot>
</span>
<span class="sbb-teaser-product__container">
<span class="sbb-teaser-product__content">
<slot>
`<div class="sbb-teaser-product__wrapper">
<a
class="sbb-action-base sbb-teaser-product"
href="https://www.sbb.ch"
>
<sbb-screen-reader-only>
</sbb-screen-reader-only>
</a>
<div class="sbb-teaser-product__content-wrapper">
<span class="sbb-teaser-product__image-container">
<slot name="image">
</slot>
</span>
<span class="sbb-teaser-product__footnote">
<slot name="footnote">
</slot>
<span class="sbb-teaser-product__container">
<span class="sbb-teaser-product__content">
<slot>
</slot>
</span>
<span class="sbb-teaser-product__footnote">
<slot name="footnote">
</slot>
</span>
</span>
</span>
</a>
</div>
</div>
`;
/* end snapshot sbb-teaser-product renders Shadow DOM */

Expand All @@ -59,8 +65,16 @@ snapshots["sbb-teaser-product renders A11y tree Firefox"] =
"children": [
{
"role": "link",
"name": "Content Footnote",
"name": "",
"value": "https://www.sbb.ch/"
},
{
"role": "text leaf",
"name": "Content"
},
{
"role": "text leaf",
"name": "Footnote"
}
]
}
Expand All @@ -76,7 +90,15 @@ snapshots["sbb-teaser-product renders A11y tree Chrome"] =
"children": [
{
"role": "link",
"name": "Content Footnote"
"name": ""
},
{
"role": "text",
"name": "Content"
},
{
"role": "text",
"name": "Footnote"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@
position: relative;
}

.sbb-teaser-product__content-wrapper {
height: fit-content;
width: fit-content;
pointer-events: none;
}

.sbb-teaser-product {
position: absolute;
inset: 0;
z-index: 1;

&:focus-visible {
:host(:not([data-focus-origin='mouse'], [data-focus-origin='touch'])) & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import type {
StoryContext,
StoryObj,
} from '@storybook/web-components';
import { nothing, type TemplateResult } from 'lit';
import { html } from 'lit';
import { html, nothing, type TemplateResult } from 'lit';

import { sbbSpread } from '../../../storybook/helpers/spread.js';
import sampleImages from '../../core/images.js';

import readme from './readme.md?raw';

import './teaser-product.js';
import '../../button/button-static.js';
import '../../image.js';
Expand Down Expand Up @@ -78,7 +78,7 @@ const defaultArgs: Args = {
withFooter: true,
slottedImg: false,
href: 'https://www.sbb.ch',
'accessibility-label': undefined,
'accessibility-label': 'Benefit from up to 70% discount, Follow the link to benefit.',
};

const content = (): TemplateResult => html`
Expand Down
10 changes: 9 additions & 1 deletion src/elements/teaser-product/teaser-product/teaser-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { SbbTeaserProductCommonElementMixin, teaserProductCommonStyle } from '..

import style from './teaser-product.scss?lit&inline';

import '../../screen-reader-only.js';

/**
* Displays a text and a footnote, combined with an image, to tease a product
*
Expand All @@ -24,7 +26,13 @@ class SbbTeaserProductElement extends SbbTeaserProductCommonElementMixin(SbbLink
protected override render(): TemplateResult {
// We render the content outside the anchor tag to allow screen readers to navigate through it
return html`
<div class="sbb-teaser-product__wrapper">${this.renderLink()} ${this.renderTemplate()}</div>
<div class="sbb-teaser-product__wrapper">
${this.renderLink(
// For SEO we add the accessibility hidden as hidden content of the link
html`<sbb-screen-reader-only>${this.accessibilityLabel}</sbb-screen-reader-only>`,
)}
<div class="sbb-teaser-product__content-wrapper">${this.renderTemplate()}</div>
</div>
`;
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/elements/teaser/__snapshots__/teaser.snapshot.spec.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ snapshots["sbb-teaser renders after centered Shadow DOM"] =
class="sbb-action-base sbb-teaser"
href="https://github.com/sbb-design-systems/lyne-components"
>
<sbb-screen-reader-only>
SBB teaser
</sbb-screen-reader-only>
</a>
<span class="sbb-teaser__container">
<span class="sbb-teaser__image-wrapper">
Expand Down Expand Up @@ -75,6 +78,9 @@ snapshots["sbb-teaser renders after with title level set Shadow DOM"] =
class="sbb-action-base sbb-teaser"
href="https://github.com/sbb-design-systems/lyne-components"
>
<sbb-screen-reader-only>
SBB teaser
</sbb-screen-reader-only>
</a>
<span class="sbb-teaser__container">
<span class="sbb-teaser__image-wrapper">
Expand Down Expand Up @@ -142,6 +148,9 @@ snapshots["sbb-teaser renders below with projected content Shadow DOM"] =
class="sbb-action-base sbb-teaser"
href="https://github.com/sbb-design-systems/lyne-components"
>
<sbb-screen-reader-only>
SBB teaser
</sbb-screen-reader-only>
</a>
<span class="sbb-teaser__container">
<span class="sbb-teaser__image-wrapper">
Expand Down Expand Up @@ -183,6 +192,10 @@ snapshots["sbb-teaser renders after centered A11y tree Chrome"] =
"role": "WebArea",
"name": "",
"children": [
{
"role": "text",
"name": "​"
},
{
"role": "link",
"name": "SBB teaser"
Expand All @@ -199,6 +212,10 @@ snapshots["sbb-teaser renders after centered A11y tree Firefox"] =
"role": "document",
"name": "",
"children": [
{
"role": "statictext",
"name": "​"
},
{
"role": "link",
"name": "SBB teaser",
Expand Down
2 changes: 0 additions & 2 deletions src/elements/teaser/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ It's important to set the `accessibilityLabel` on the `<sbb-teaser>`, which desc

The description text is wrapped into an `<p>` element to guarantee the semantic meaning.

Avoid slotting block elements (e.g. `<div>`) as this violates semantic rules and can have negative effects on screen readers.

<!-- Auto Generated Below -->

## Properties
Expand Down
8 changes: 5 additions & 3 deletions src/elements/teaser/teaser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@
}

.sbb-teaser__wrapper {
display: flex;
position: relative;
cursor: pointer;

@include sbb.zero-width-space;
}

.sbb-teaser {
text-decoration: none;
position: absolute;
inset: 0;
z-index: 1;

@include sbb.zero-width-space;

// Hide focus outline when focus origin is mouse or touch. This is being used as a workaround in various components.
:host(:not([data-focus-origin='mouse'], [data-focus-origin='touch'])) &:focus-visible {
Expand All @@ -72,6 +73,7 @@
gap: var(--sbb-teaser-gap);
max-width: 100%;
width: 100%;
pointer-events: none;
}

.sbb-teaser__text {
Expand Down
9 changes: 8 additions & 1 deletion src/elements/teaser/teaser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { SbbTitleLevel } from '../title.js';
import style from './teaser.scss?lit&inline';

import '../chip-label.js';
import '../screen-reader-only.js';
import '../title.js';

/**
Expand Down Expand Up @@ -45,7 +46,13 @@ class SbbTeaserElement extends SbbLinkBaseElement {
protected override render(): TemplateResult {
// We render the content outside the anchor tag to allow screen readers to navigate through it
return html`
<div class="sbb-teaser__wrapper">${this.renderLink()} ${this.renderContent()}</div>
<div class="sbb-teaser__wrapper">
${this.renderLink(
// For SEO we add the accessibility hidden as hidden content of the link
html`<sbb-screen-reader-only>${this.accessibilityLabel}</sbb-screen-reader-only>`,
)}
${this.renderContent()}
</div>
`;
}

Expand Down

0 comments on commit b188112

Please sign in to comment.