Skip to content
This repository has been archived by the owner on Nov 9, 2024. It is now read-only.

Commit

Permalink
fix: bail if aria-expanded attribute is present onCreate
Browse files Browse the repository at this point in the history
resolves #690
  • Loading branch information
atomiks committed Jan 31, 2020
1 parent 129366b commit d87392b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/createTippy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ export default function createTippy(
popper._tippy = instance;

const pluginsHooks = plugins.map(plugin => plugin.fn(instance));
const hadAriaExpandedAttributeOnCreate = reference.hasAttribute(
'aria-expanded',
);

addListenersToTriggerTarget();
handleAriaExpandedAttribute();
Expand Down Expand Up @@ -265,6 +268,13 @@ export default function createTippy(
}

function handleAriaExpandedAttribute(): void {
// If the user has specified `aria-expanded` on their reference when the
// instance was created, we have to assume they're controlling it externally
// themselves
if (hadAriaExpandedAttributeOnCreate) {
return;
}

const nodes = normalizeToArray(instance.props.triggerTarget || reference);

nodes.forEach(node => {
Expand Down
7 changes: 7 additions & 0 deletions test/integration/createTippy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ describe('createTippy', () => {

expect(instance.plugins).toEqual([animateFill]);
});

it('does not remove an existing `aria-expanded` attribute', () => {
const ref = h('div', {'aria-expanded': 'true'});
instance = createTippy(ref, {interactive: false});

expect(ref.hasAttribute('aria-expanded')).toBe(true);
});
});

describe('instance.destroy()', () => {
Expand Down

0 comments on commit d87392b

Please sign in to comment.