-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set login overlay role to dialog, use title as aria-label (#7723) (
#7741) Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
- Loading branch information
1 parent
ed4c483
commit 8c6202b
Showing
7 changed files
with
128 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2018 - 2024 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js'; | ||
import { SlotObserver } from '@vaadin/component-base/src/slot-observer'; | ||
import { generateUniqueId } from '@vaadin/component-base/src/unique-id-utils'; | ||
import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js'; | ||
|
||
/** | ||
* @polymerMixin | ||
* @mixes DirMixin | ||
* @mixes OverlayMixin | ||
*/ | ||
export const LoginOverlayWrapperMixin = (superClass) => | ||
class LoginOverlayWrapperMixin extends OverlayMixin(DirMixin(superClass)) { | ||
static get properties() { | ||
return { | ||
/** | ||
* Title of the application. | ||
*/ | ||
title: { | ||
type: String, | ||
observer: '_titleChanged', | ||
}, | ||
|
||
/** | ||
* Application description. Displayed under the title. | ||
*/ | ||
description: { | ||
type: String, | ||
}, | ||
}; | ||
} | ||
|
||
/** @protected */ | ||
ready() { | ||
super.ready(); | ||
|
||
// Use slot observer instead of slot controller since the latter | ||
// does not work well with teleporting (it removes custom title). | ||
const slot = this.shadowRoot.querySelector('slot[name="title"]'); | ||
this._titleSlotObserver = new SlotObserver(slot, () => { | ||
const title = slot.assignedElements({ flatten: true })[0]; | ||
if (!title) { | ||
return; | ||
} | ||
|
||
// Only set ID on the custom slotted title and link it using | ||
// aria-labelledby as the default title is in the shadow DOM. | ||
if (title.getAttribute('part') === 'title') { | ||
this.setAttribute('aria-label', this.title); | ||
this.removeAttribute('aria-labelledby'); | ||
} else { | ||
if (!title.id) { | ||
title.id = `login-overlay-title-${generateUniqueId()}`; | ||
} | ||
this.removeAttribute('aria-label'); | ||
this.setAttribute('aria-labelledby', title.id); | ||
} | ||
}); | ||
} | ||
|
||
/** @private */ | ||
_titleChanged(title) { | ||
if (title && this.hasAttribute('aria-label')) { | ||
this.setAttribute('aria-label', title); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters