From e4988ebf6359338d4b98937921023fbc29c5e611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pha=CC=A3m=20Tua=CC=82=CC=81n?= Date: Tue, 2 Oct 2018 23:30:26 +0700 Subject: [PATCH] Set and remove element aria-describedby base on popper To fix aria attribute do not have valid value, issue: https://github.com/tvkhoa/react-tippy/issues/89 As describedby need to point to a valid id, that means id that exists, while current implementation set it from beginning and keep it there even when the popper is hidden - removed from DOM. This update will help solve issue as we only set it when show and remove when hide the popper --- src/Tooltip/js/core/createTooltips.js | 1 - src/Tooltip/js/tippy.js | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Tooltip/js/core/createTooltips.js b/src/Tooltip/js/core/createTooltips.js index b8c4cc2..8189bdf 100644 --- a/src/Tooltip/js/core/createTooltips.js +++ b/src/Tooltip/js/core/createTooltips.js @@ -31,7 +31,6 @@ export default function createTooltips(els) { if (!title && !html) return a el.setAttribute('data-tooltipped', '') - el.setAttribute('aria-describedby', `tippy-tooltip-${id}`) removeTitle(el) const popper = createPopperElement(id, title, settings) diff --git a/src/Tooltip/js/tippy.js b/src/Tooltip/js/tippy.js index ae4a03f..87cf5b0 100644 --- a/src/Tooltip/js/tippy.js +++ b/src/Tooltip/js/tippy.js @@ -211,6 +211,7 @@ class Tippy { popper.style.visibility = 'visible' popper.setAttribute('aria-hidden', 'false') + el.setAttribute('aria-describedby', popper.id) // Wait for popper's position to update defer(() => { @@ -303,6 +304,7 @@ class Tippy { popper.style.visibility = 'hidden' popper.setAttribute('aria-hidden', 'true') + el.removeAttribute('aria-describedby') applyTransitionDuration([tooltip, circle, circle ? content : null], _duration)