-
Notifications
You must be signed in to change notification settings - Fork 87
refactor!: update tooltip overlay to use native popover #9760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
4b5ea9f
3898875
b37d6f7
5cce31b
ce925bb
9ea9c00
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 |
|---|---|---|
|
|
@@ -330,7 +330,6 @@ export const TooltipMixin = (superClass) => | |
| */ | ||
| text: { | ||
| type: String, | ||
| observer: '__textChanged', | ||
| }, | ||
|
|
||
| /** | ||
|
|
@@ -366,26 +365,9 @@ export const TooltipMixin = (superClass) => | |
| type: Boolean, | ||
| sync: true, | ||
| }, | ||
|
|
||
| /** @private */ | ||
| _srLabel: { | ||
| type: Object, | ||
| }, | ||
|
|
||
| /** @private */ | ||
| _overlayContent: { | ||
| type: String, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| static get observers() { | ||
| return [ | ||
| '__generatorChanged(_overlayElement, generator, context)', | ||
| '__updateSrLabelText(_srLabel, _overlayContent)', | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the default focus delay to be used by all tooltip instances, | ||
| * except for those that have focus delay configured using property. | ||
|
|
@@ -420,7 +402,6 @@ export const TooltipMixin = (superClass) => | |
| super(); | ||
|
|
||
| this._uniqueId = `vaadin-tooltip-${generateUniqueId()}`; | ||
| this._renderer = this.__tooltipRenderer.bind(this); | ||
|
|
||
| this.__onFocusin = this.__onFocusin.bind(this); | ||
| this.__onFocusout = this.__onFocusout.bind(this); | ||
|
|
@@ -467,19 +448,24 @@ export const TooltipMixin = (superClass) => | |
|
|
||
| this._overlayElement = this.$.overlay; | ||
|
|
||
| this._srLabelController = new SlotController(this, 'sr-label', 'div', { | ||
| this.__contentController = new SlotController(this, 'overlay', 'div', { | ||
| initializer: (element) => { | ||
| element.id = this._uniqueId; | ||
| element.setAttribute('role', 'tooltip'); | ||
| this._srLabel = element; | ||
| this.__contentNode = element; | ||
| }, | ||
| }); | ||
| this.addController(this._srLabelController); | ||
| this.addController(this.__contentController); | ||
| } | ||
|
|
||
| /** @private */ | ||
| __computeOpened(manual, opened, autoOpened, connected) { | ||
| return connected && (manual ? opened : autoOpened); | ||
| /** @protected */ | ||
| updated(props) { | ||
| super.updated(props); | ||
|
|
||
| if (props.has('text') || props.has('generator') || props.has('context')) { | ||
| this.__updateContent(); | ||
|
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. I'm not sure about this method. It mainly exists because of an ugly internal hack which is likely used in some customer project and relies on patching 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. Doesn't really hurt to keep it. |
||
| this.$.overlay.toggleAttribute('hidden', this.__contentNode.textContent.trim() === ''); | ||
| } | ||
| } | ||
|
|
||
| /** @private */ | ||
|
|
@@ -688,18 +674,8 @@ export const TooltipMixin = (superClass) => | |
| } | ||
|
|
||
| /** @private */ | ||
| __textChanged(text, oldText) { | ||
| if (this._overlayElement && (text || oldText)) { | ||
| this._overlayElement.requestContentUpdate(); | ||
| } | ||
| } | ||
|
|
||
| /** @private */ | ||
| __tooltipRenderer(root) { | ||
| root.textContent = typeof this.generator === 'function' ? this.generator(this.context) : this.text; | ||
|
|
||
| // Update the sr-only label text content | ||
| this._overlayContent = root.textContent; | ||
| __updateContent() { | ||
| this.__contentNode.textContent = typeof this.generator === 'function' ? this.generator(this.context) : this.text; | ||
| } | ||
|
|
||
| /** @private */ | ||
|
|
@@ -723,23 +699,4 @@ export const TooltipMixin = (superClass) => | |
| }); | ||
| } | ||
| } | ||
|
|
||
| /** @private */ | ||
| __generatorChanged(overlayElement, generator, context) { | ||
| if (overlayElement) { | ||
| if (generator !== this.__oldTextGenerator || context !== this.__oldContext) { | ||
| overlayElement.requestContentUpdate(); | ||
| } | ||
|
|
||
| this.__oldTextGenerator = generator; | ||
| this.__oldContext = context; | ||
| } | ||
| } | ||
|
|
||
| /** @private */ | ||
| __updateSrLabelText(srLabel, textContent) { | ||
| if (srLabel) { | ||
| srLabel.textContent = textContent; | ||
| } | ||
| } | ||
| }; | ||
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.
Previously, tooltip was preserving the text after closing, which is rather unexpected. Tests didn't catch that because the IT assertion returned
nullif novaadin-tooltip-overlaywas found in the document.