diff --git a/packages/core/addon/components/eui-tool-tip/index.hbs b/packages/core/addon/components/eui-tool-tip/index.hbs index faa6071ff..c7af105e5 100644 --- a/packages/core/addon/components/eui-tool-tip/index.hbs +++ b/packages/core/addon/components/eui-tool-tip/index.hbs @@ -7,8 +7,8 @@ {{else}} {{#if hasAnchorBlock}} {{yield this.id to="anchor"}} diff --git a/packages/core/addon/components/eui-tool-tip/index.ts b/packages/core/addon/components/eui-tool-tip/index.ts index c8ffc0fc1..8a7bbe7ef 100644 --- a/packages/core/addon/components/eui-tool-tip/index.ts +++ b/packages/core/addon/components/eui-tool-tip/index.ts @@ -22,6 +22,7 @@ interface ToolTipStyles { right?: string | 'auto'; opacity?: string; visibility?: 'hidden'; + display?: 'inlineBlock'; } const displayToClassNameMap = { @@ -39,7 +40,8 @@ const DEFAULT_TOOLTIP_STYLES: ToolTipStyles = { // the tooltip before it is positioned opacity: '0', // prevent accidental mouse interaction while positioning - visibility: 'hidden' + visibility: 'hidden', + display: 'inlineBlock' }; type EuiTooltipArgs = { @@ -85,6 +87,8 @@ type EuiTooltipArgs = { * hidden. */ onMouseOut?: (event: MouseEvent) => void; + onFocus?: () => void; + onBlur?: () => void; }; export default class EuiToolTip extends Component { @@ -96,6 +100,7 @@ export default class EuiToolTip extends Component { //STATE @tracked visible = false; + @tracked hasFocus = false; @tracked calculatedPosition: ToolTipPositions = this.position; @tracked toolTipStyles: ToolTipStyles = DEFAULT_TOOLTIP_STYLES; @tracked arrowStyles: undefined | { left: string; top: string }; @@ -123,24 +128,22 @@ export default class EuiToolTip extends Component { @action setupAttachToHandlers(): void { - if (this.attachTo) { + if (this._attachTo) { this.attachTo?.addEventListener('mousemove', this.showToolTip); - this.attachTo?.addEventListener('keyup', this.onKeyUp); - this.attachTo?.addEventListener('focusin', this.showToolTip); + this.attachTo?.addEventListener('focusin', this.onFocus); this.attachTo?.addEventListener('mouseout', this.onMouseOut); - this.attachTo?.addEventListener('focusout', this.hideToolTip); + this.attachTo?.addEventListener('focusout', this.onBlur); this.positionToolTip(); } } @action removeAttachToHandlers(): void { - if (this.attachTo) { + if (this._attachTo) { this.attachTo?.removeEventListener('mousemove', this.showToolTip); - this.attachTo?.removeEventListener('keyup', this.onKeyUp); - this.attachTo?.removeEventListener('focusin', this.showToolTip); + this.attachTo?.removeEventListener('focusin', this.onFocus); this.attachTo?.removeEventListener('mouseout', this.onMouseOut); - this.attachTo?.removeEventListener('focusout', this.hideToolTip); + this.attachTo?.removeEventListener('focusout', this.onBlur); } } @@ -163,7 +166,6 @@ export default class EuiToolTip extends Component { super.willDestroy(); this.clearAnimationTimeout(); this.removeAttachToHandlers(); - window.removeEventListener('mousemove', this.hasFocusMouseMoveListener); } @action @@ -298,6 +300,18 @@ export default class EuiToolTip extends Component { } } + @action + onFocus(): void { + this.hasFocus = true; + this.showToolTip(); + } + + @action + onBlur(): void { + this.hasFocus = false; + this.hideToolTip(); + } + @action onMouseOut(event: MouseEvent): void { // Prevent mousing over children from hiding the tooltip by testing for whether the mouse has @@ -307,7 +321,9 @@ export default class EuiToolTip extends Component { (this._anchor != null && !this._anchor.contains(event.relatedTarget as Node)) ) { - this.hideToolTip(); + if (!this.hasFocus) { + this.hideToolTip(); + } } if (this.args.onMouseOut) { diff --git a/packages/core/docs/display/tool-tip-demo/demo1.md b/packages/core/docs/display/tool-tip-demo/demo1.md index e2bf07de6..1a03debf4 100644 --- a/packages/core/docs/display/tool-tip-demo/demo1.md +++ b/packages/core/docs/display/tool-tip-demo/demo1.md @@ -36,8 +36,7 @@ order: 1

- This tooltip has a long delay because it might be in a repeatable - component + This tooltip has a long delay because it might be in a repeatable component Wink @@ -53,40 +52,68 @@ order: 1

- + I am a block level tooltip, applied to a button with fullWidth

- - + + - If you want to attach and control the ToolTip to something programatically you can optionally pass an attachTo string or element - and use the content named block, also you can pass isShown as true to show the tooltip without user interaction + If you want to attach and control the ToolTip to something programatically you + can optionally pass an attachTo string or element and use the content named + block, also you can pass isShown as true to show the tooltip without user + interaction - + - + You can hover me, attach to 1 - + You can hover me, attach to 2 - + You can hover me, attach to 3 - + {{if this.isShown "isShown true" "isShown false"}} - + <:content>

Works on any kind of element — buttons, inputs, you name it! diff --git a/packages/core/docs/display/tool-tip-demo/demo2.md b/packages/core/docs/display/tool-tip-demo/demo2.md index 726b7123b..36b2957d3 100644 --- a/packages/core/docs/display/tool-tip-demo/demo2.md +++ b/packages/core/docs/display/tool-tip-demo/demo2.md @@ -6,7 +6,7 @@ order: 2 ```hbs template - +

- Pass a position utility class via iconProps to shift - for better alignment. - + Pass a position utility class via iconProps to shift for better alignment. + <:content> This was passed .eui-alignTop diff --git a/packages/core/docs/display/tool-tip.md b/packages/core/docs/display/tool-tip.md index 295c95083..320f3c7dc 100644 --- a/packages/core/docs/display/tool-tip.md +++ b/packages/core/docs/display/tool-tip.md @@ -2,8 +2,8 @@

- Tool Tip + Tooltip

- \ No newline at end of file +