@justeattakeaway/pie-cookie-banner 1.10.21 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cdn_dist/index.d.ts +15 -0
- package/cdn_dist/index.js +20 -13
- package/custom-elements.json +30 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.js +279 -254
- package/dist/react.d.ts +15 -0
- package/package.json +10 -10
- package/src/defs.ts +9 -0
- package/src/index.ts +38 -5
package/dist/react.d.ts
CHANGED
|
@@ -102,6 +102,13 @@ export declare interface CookieBannerProps {
|
|
|
102
102
|
* When false (default), links open in a new browser tab (`target="_blank"`).
|
|
103
103
|
*/
|
|
104
104
|
openLinksInSameTab?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* When true, focus moves to the banner dialog when it is displayed on mount,
|
|
107
|
+
* so screen readers announce it. Only set this when the banner is opened
|
|
108
|
+
* in response to a user action; on initial page load focus must remain untouched.
|
|
109
|
+
* When false (default), the banner does not take focus on mount.
|
|
110
|
+
*/
|
|
111
|
+
shouldFocusOnOpen?: boolean;
|
|
105
112
|
}
|
|
106
113
|
|
|
107
114
|
export declare const Country: {
|
|
@@ -176,14 +183,22 @@ declare class PieCookieBanner_2 extends PieElement implements CookieBannerProps
|
|
|
176
183
|
country: string;
|
|
177
184
|
language: string;
|
|
178
185
|
openLinksInSameTab: boolean;
|
|
186
|
+
shouldFocusOnOpen: boolean;
|
|
179
187
|
_preferencesNodes: NodeListOf<PieSwitch>;
|
|
188
|
+
private _bannerContainer;
|
|
180
189
|
/**
|
|
181
190
|
* Returns the target attribute value for external links based on the openLinksInSameTab prop.
|
|
182
191
|
* - false (default): returns '_blank' (new tab)
|
|
183
192
|
* - true: returns '_self' (same tab)
|
|
184
193
|
*/
|
|
185
194
|
private get _linkTargetAttribute();
|
|
195
|
+
firstUpdated(): void;
|
|
186
196
|
updated(changedProperties: PropertyValues<this>): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Moves focus to the banner dialog container.
|
|
199
|
+
* The container uses tabindex="-1", so it is only focusable programmatically.
|
|
200
|
+
*/
|
|
201
|
+
private _focusBanner;
|
|
187
202
|
private _setLocaleBasedOnCountryAndLanguage;
|
|
188
203
|
/**
|
|
189
204
|
* Gets the locale string for the requested language and country.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-cookie-banner",
|
|
3
3
|
"description": "PIE Design System Cookie Banner built using Web Components",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.11.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/justeattakeaway/pie",
|
|
@@ -49,19 +49,19 @@
|
|
|
49
49
|
"author": "Just Eat Takeaway.com - Design System Team",
|
|
50
50
|
"license": "Apache-2.0",
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@justeattakeaway/pie-components-config": "0.21.
|
|
52
|
+
"@justeattakeaway/pie-components-config": "0.21.5",
|
|
53
53
|
"@justeattakeaway/pie-css": "1.9.1",
|
|
54
|
-
"@justeattakeaway/pie-monorepo-utils": "0.9.
|
|
54
|
+
"@justeattakeaway/pie-monorepo-utils": "0.9.12",
|
|
55
55
|
"@justeattakeaway/pie-wrapper-react": "0.14.5"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@justeattakeaway/pie-button": "1.15.
|
|
59
|
-
"@justeattakeaway/pie-divider": "1.5.
|
|
60
|
-
"@justeattakeaway/pie-icon-button": "2.8.
|
|
61
|
-
"@justeattakeaway/pie-link": "1.5.
|
|
62
|
-
"@justeattakeaway/pie-modal": "1.27.
|
|
63
|
-
"@justeattakeaway/pie-switch": "2.7.
|
|
64
|
-
"@justeattakeaway/pie-webc-core": "22.0.
|
|
58
|
+
"@justeattakeaway/pie-button": "1.15.1",
|
|
59
|
+
"@justeattakeaway/pie-divider": "1.5.38",
|
|
60
|
+
"@justeattakeaway/pie-icon-button": "2.8.1",
|
|
61
|
+
"@justeattakeaway/pie-link": "1.5.9",
|
|
62
|
+
"@justeattakeaway/pie-modal": "1.27.15",
|
|
63
|
+
"@justeattakeaway/pie-switch": "2.7.7",
|
|
64
|
+
"@justeattakeaway/pie-webc-core": "22.0.1",
|
|
65
65
|
"dompurify": "3.4.8"
|
|
66
66
|
},
|
|
67
67
|
"customElements": "custom-elements.json",
|
package/src/defs.ts
CHANGED
|
@@ -146,6 +146,14 @@ export interface CookieBannerProps {
|
|
|
146
146
|
* When false (default), links open in a new browser tab (`target="_blank"`).
|
|
147
147
|
*/
|
|
148
148
|
openLinksInSameTab?: boolean;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* When true, focus moves to the banner dialog when it is displayed on mount,
|
|
152
|
+
* so screen readers announce it. Only set this when the banner is opened
|
|
153
|
+
* in response to a user action; on initial page load focus must remain untouched.
|
|
154
|
+
* When false (default), the banner does not take focus on mount.
|
|
155
|
+
*/
|
|
156
|
+
shouldFocusOnOpen?: boolean;
|
|
149
157
|
}
|
|
150
158
|
|
|
151
159
|
/**
|
|
@@ -228,6 +236,7 @@ export const defaultProps: DefaultProps = {
|
|
|
228
236
|
personalizedDescription: '',
|
|
229
237
|
cookieTechnologiesLink: '',
|
|
230
238
|
openLinksInSameTab: false,
|
|
239
|
+
shouldFocusOnOpen: false,
|
|
231
240
|
};
|
|
232
241
|
|
|
233
242
|
// Available locale files
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from 'lit';
|
|
7
7
|
import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
|
|
8
8
|
import {
|
|
9
|
-
property, state, queryAll,
|
|
9
|
+
property, state, query, queryAll,
|
|
10
10
|
} from 'lit/decorators.js';
|
|
11
11
|
import { repeat } from 'lit/directives/repeat.js';
|
|
12
12
|
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
|
@@ -92,9 +92,15 @@ export class PieCookieBanner extends PieElement implements CookieBannerProps {
|
|
|
92
92
|
@property({ type: Boolean })
|
|
93
93
|
public openLinksInSameTab = defaultProps.openLinksInSameTab;
|
|
94
94
|
|
|
95
|
+
@property({ type: Boolean })
|
|
96
|
+
public shouldFocusOnOpen = defaultProps.shouldFocusOnOpen;
|
|
97
|
+
|
|
95
98
|
@queryAll('pie-switch')
|
|
96
99
|
_preferencesNodes!: NodeListOf<PieSwitch>;
|
|
97
100
|
|
|
101
|
+
@query('[data-test-id="pie-cookie-banner"]')
|
|
102
|
+
private _bannerContainer!: HTMLElement;
|
|
103
|
+
|
|
98
104
|
/**
|
|
99
105
|
* Returns the target attribute value for external links based on the openLinksInSameTab prop.
|
|
100
106
|
* - false (default): returns '_blank' (new tab)
|
|
@@ -104,11 +110,31 @@ export class PieCookieBanner extends PieElement implements CookieBannerProps {
|
|
|
104
110
|
return this.openLinksInSameTab ? '_self' : '_blank';
|
|
105
111
|
}
|
|
106
112
|
|
|
113
|
+
firstUpdated () {
|
|
114
|
+
// Only take focus on mount when the banner was opened by a user action
|
|
115
|
+
if (this.shouldFocusOnOpen && !this._isCookieBannerHidden) {
|
|
116
|
+
this._focusBanner();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
107
120
|
async updated (changedProperties: PropertyValues<this>) {
|
|
108
121
|
// Re-fetch locale when country or language changes
|
|
109
122
|
if (changedProperties.has('language') || changedProperties.has('country')) {
|
|
110
123
|
await this._setLocaleBasedOnCountryAndLanguage(this.language, this.country);
|
|
111
124
|
}
|
|
125
|
+
|
|
126
|
+
// Move focus to the banner whenever it reappears, so screen readers announce the dialog
|
|
127
|
+
if (changedProperties.get('_isCookieBannerHidden' as keyof PieCookieBanner) === true && !this._isCookieBannerHidden) {
|
|
128
|
+
this._focusBanner();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Moves focus to the banner dialog container.
|
|
134
|
+
* The container uses tabindex="-1", so it is only focusable programmatically.
|
|
135
|
+
*/
|
|
136
|
+
private _focusBanner () : void {
|
|
137
|
+
this._bannerContainer?.focus();
|
|
112
138
|
}
|
|
113
139
|
|
|
114
140
|
// Dynamically import locale JSON based on country and language
|
|
@@ -342,10 +368,17 @@ export class PieCookieBanner extends PieElement implements CookieBannerProps {
|
|
|
342
368
|
@pie-modal-back="${this._displayCookieBanner}">
|
|
343
369
|
${this.renderModalContent()}
|
|
344
370
|
</pie-modal>
|
|
345
|
-
<
|
|
346
|
-
|
|
371
|
+
<div
|
|
372
|
+
data-test-id="pie-cookie-banner"
|
|
373
|
+
class="c-cookieBanner"
|
|
374
|
+
role="dialog"
|
|
375
|
+
aria-labelledby="cookie-banner-title"
|
|
376
|
+
aria-describedby="cookie-banner-text"
|
|
377
|
+
tabindex="-1"
|
|
378
|
+
?isCookieBannerHidden=${this._isCookieBannerHidden}>
|
|
379
|
+
<h2 id="cookie-banner-title" class="c-cookieBanner-title">${this._localiseText('banner.title')}</h2>
|
|
347
380
|
<div class="c-cookieBanner-body" data-test-id="banner-description">
|
|
348
|
-
<p>${this._localiseRichText('banner.description')}</p>
|
|
381
|
+
<p id="cookie-banner-text">${this._localiseRichText('banner.description')}</p>
|
|
349
382
|
</div>
|
|
350
383
|
|
|
351
384
|
<div class="c-cookieBanner-actions">
|
|
@@ -374,7 +407,7 @@ export class PieCookieBanner extends PieElement implements CookieBannerProps {
|
|
|
374
407
|
${this._localiseText('banner.cta.managePreferences')}
|
|
375
408
|
</pie-link>
|
|
376
409
|
</div>
|
|
377
|
-
</
|
|
410
|
+
</div>`;
|
|
378
411
|
}
|
|
379
412
|
|
|
380
413
|
// Renders a `CSSResult` generated from SCSS by Vite
|