feat(overlays): add invokerRelation option (#672)
This commit is contained in:
parent
b58aa65377
commit
d7cfab016f
2 changed files with 17 additions and 2 deletions
|
|
@ -246,9 +246,11 @@ export class OverlayController {
|
|||
this.contentNode.setAttribute('id', this._contentId);
|
||||
}
|
||||
if (this.isTooltip) {
|
||||
// TODO: (@tlouisse) this could also be labelledby.
|
||||
if (this.invokerNode) {
|
||||
this.invokerNode.setAttribute('aria-describedby', this._contentId);
|
||||
this.invokerNode.setAttribute(
|
||||
this.invokerRelation === 'label' ? 'aria-labelledby' : 'aria-describedby',
|
||||
this._contentId,
|
||||
);
|
||||
}
|
||||
this.contentNode.setAttribute('role', 'tooltip');
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1167,6 +1167,19 @@ describe('OverlayController', () => {
|
|||
expect(ctrl.invokerNode.getAttribute('aria-describedby')).to.equal(ctrl._contentId);
|
||||
});
|
||||
|
||||
it('adds [aria-labelledby] on invoker when invokerRelation is label', async () => {
|
||||
const invokerNode = await fixture('<div role="button">invoker</div>');
|
||||
const ctrl = new OverlayController({
|
||||
...withLocalTestConfig(),
|
||||
handlesAccessibility: true,
|
||||
isTooltip: true,
|
||||
invokerRelation: 'label',
|
||||
invokerNode,
|
||||
});
|
||||
expect(ctrl.invokerNode.getAttribute('aria-describedby')).to.equal(null);
|
||||
expect(ctrl.invokerNode.getAttribute('aria-labelledby')).to.equal(ctrl._contentId);
|
||||
});
|
||||
|
||||
it('adds [role=tooltip] on content', async () => {
|
||||
const invokerNode = await fixture('<div role="button">invoker</div>');
|
||||
const ctrl = new OverlayController({
|
||||
|
|
|
|||
Loading…
Reference in a new issue