Skip to content

Commit

Permalink
fix(ld-cookie-consent): focus disclaimer on showDisclaimer even if al…
Browse files Browse the repository at this point in the history
…ready shown
  • Loading branch information
borisdiakur committed Nov 7, 2022
1 parent 94cfa4c commit 97fec8a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/liquid/components/ld-cookie-consent/ld-cookie-consent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class LdCookieConsent {
} | null
@State() private selectedCategories: Set<string> = new Set()

private disclaimerRef: HTMLDivElement
private modalRef: HTMLLdModalElement
private config: LdCookieConsentConfig = {
backdropBlur: true,
Expand Down Expand Up @@ -184,6 +185,7 @@ export class LdCookieConsent {
async showDisclaimer(delay?: number) {
const cb = () => {
this.isDisclaimerVisible = true
this.disclaimerRef?.focus()
this.ldCookieConsentDisclaimerShow.emit()
}
if (delay) {
Expand Down Expand Up @@ -357,6 +359,7 @@ export class LdCookieConsent {
this.focus()
}}
part="disclaimer"
ref={(ref) => (this.disclaimerRef = ref)}
role="dialog"
tabIndex={this.isDisclaimerVisible ? -1 : undefined}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,33 @@ describe('ld-cookie-consent', () => {
expect(disclaimerShowHandler).toHaveBeenCalledTimes(1)
})

it('sets focus on disclaimer when calling method showDisclaimer even if already shown', async () => {
const page = await newSpecPage({
components: [LdCookieConsent],
template: () => (
<ld-cookie-consent
settings={{
mode: 'notice-only',
privacyStatementURL: '#',
showOnLoadDelay: 0,
}}
/>
),
})
const ldCookieConsent = getLdCookieConsent(page)
const disclaimer = getDisclaimer(page)
disclaimer.focus = jest.fn()
await transitionEnd(page)
await page.waitForChanges()

expect(disclaimer).toHaveClass('ld-cookie-consent__disclaimer--visible')
expect(disclaimer.focus).toHaveBeenCalledTimes(1)

ldCookieConsent.showDisclaimer()
await page.waitForChanges()
expect(disclaimer.focus).toHaveBeenCalledTimes(2)
})

it('shows up on load without delay', async () => {
const page = await newSpecPage({
components: [LdCookieConsent],
Expand Down

1 comment on commit 97fec8a

@vercel
Copy link

@vercel vercel bot commented on 97fec8a Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

liquid – ./

liquid-oxygen.vercel.app
liquid-git-main-uxsd.vercel.app
liquid-uxsd.vercel.app

Please sign in to comment.