-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(tooltip): interpolate the tooltip text when adding it to the aria-label #8170
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ angular | |
* @param {string=} md-direction Which direction would you like the tooltip to go? Supports left, right, top, and bottom. Defaults to bottom. | ||
*/ | ||
function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdTheming, $rootElement, | ||
$animate, $q) { | ||
$animate, $q, $interpolate) { | ||
|
||
var TOOLTIP_SHOW_DELAY = 0; | ||
var TOOLTIP_WINDOW_EDGE_SPACE = 8; | ||
|
@@ -150,11 +150,22 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe | |
element.remove(); | ||
attributeObserver && attributeObserver.disconnect(); | ||
}); | ||
|
||
// Updates the aria-label when the element text changes. This watch | ||
// doesn't need to be set up if the element doesn't have any data | ||
// bindings. | ||
if (element.text().indexOf($interpolate.startSymbol()) > -1) { | ||
scope.$watch(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huge performance impact with large lists where each item as a tooltip. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, I'll try to rework it and keep this one as a fallback for the case where a mutation observer isn't supported. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A question about the mutation observer: In order to get it to fire for text changes, the |
||
return element.text().trim(); | ||
}, addAriaLabel); | ||
} | ||
} | ||
|
||
function addAriaLabel () { | ||
if (!parent.attr('aria-label') && !parent.text().trim()) { | ||
parent.attr('aria-label', element.text().trim()); | ||
function addAriaLabel (override) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See ^^ regarding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if ((override || !parent.attr('aria-label')) && !parent.text().trim()) { | ||
var rawText = override || element.text().trim(); | ||
var interpolatedText = $interpolate(rawText)(parent.scope()); | ||
parent.attr('aria-label', interpolatedText); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about ngMaterial's
aria.js
features?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the way it was done previously, but I'll look at the Material aria provider.