From b49292d566f9c22bc613cd4adb09216ab1c27f37 Mon Sep 17 00:00:00 2001 From: Adam DeHaven Date: Fri, 20 Oct 2023 12:18:42 -0400 Subject: [PATCH 1/4] feat(ktooltip): hide tooltip if no label or content --- docs/components/tooltip.md | 48 ++++++++++++++++++++++++---- src/components/KTooltip/KTooltip.vue | 33 +++++++++++++------ 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/docs/components/tooltip.md b/docs/components/tooltip.md index 82a920543b..4d8aecadf7 100644 --- a/docs/components/tooltip.md +++ b/docs/components/tooltip.md @@ -16,9 +16,7 @@ ### label -Here you can pass in the text to display in the toolip. - -- `I am a new sample label` +Here you can pass in the text to display in the tooltip. Sample Button @@ -30,8 +28,28 @@ Here you can pass in the text to display in the toolip. ``` +When using the `label` prop (or the [`content` slot](#content)), passing a value of `undefined`, an empty string, or no `content` slot content will prevent the tooltip from showing, while still displaying your `default` slot content. + + + Hover me + + +```html + + Hover me + + + +``` + :::warning NOTE -KTooltip won't be triggered if the element you pass through `default` slot has `disabled` attribute. You can get around that by wrapping your disabled element around an additional tag, like shown in the example below. +KTooltip won't be triggered if the element you pass through `default` slot has `disabled` attribute. You can get around that by wrapping your disabled element around an additional tag, like shown in the example below. ::: @@ -131,7 +149,9 @@ You can set the maximum width of a Tooltip with the `maxWidth` property. `maxWid ## Slots -- `Default` There is a main slot that takes in the element you want the popover to be triggered over. +### default + +The `default` slot takes in the element you want the popover to be triggered over. ```html @@ -140,7 +160,9 @@ You can set the maximum width of a Tooltip with the `maxWidth` property. `maxWid ``` -- `Content` This allows you to slot in any html content +### content + +The content slot allows you to slot in any html content  ✌🏻 @@ -186,6 +208,20 @@ Example: ``` + + - -```html - - - - - - - - -``` - ### placement This is where the tooltip will appear - by default it appears on top. From 00f1a6a23eb5af114ba7611b18cc929f3b48c86a Mon Sep 17 00:00:00 2001 From: Adam DeHaven Date: Fri, 20 Oct 2023 12:54:18 -0400 Subject: [PATCH 3/4] test: add prop test --- src/components/KTooltip/KTooltip.cy.ts | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/components/KTooltip/KTooltip.cy.ts b/src/components/KTooltip/KTooltip.cy.ts index f3169cc7a6..533a0e4df8 100644 --- a/src/components/KTooltip/KTooltip.cy.ts +++ b/src/components/KTooltip/KTooltip.cy.ts @@ -1,5 +1,6 @@ import { mount } from 'cypress/vue' import KTooltip from '@/components/KTooltip/KTooltip.vue' +import { h } from 'vue' const positions = ['top', 'topStart', 'topEnd', 'left', 'leftStart', 'leftEnd', 'right', 'rightStart', 'rightEnd', 'bottom', 'bottomStart', 'bottomEnd'] @@ -13,19 +14,45 @@ const positions = ['top', 'topStart', 'topEnd', 'left', 'leftStart', 'leftEnd', */ const rendersCorrectPosition = (variant: string) => { it(`renders tooltip to the ${variant} side`, () => { + const text = 'Button text' + mount(KTooltip, { props: { testMode: true, placement: variant, label: `I'm on the ${variant} side!`, + trigger: 'click', + }, + slots: { + default: () => h('button', {}, text), }, }) - cy.get('.k-tooltip').should('have.text', `I'm on the ${variant} side!`) + cy.get('button').click() + + cy.get('.k-tooltip').should('be.visible').and('not.have.class', 'k-tooltip-hidden').and('have.text', `I'm on the ${variant} side!`) }) } describe('KTooltip', () => { // Loop through varients positions.map(p => rendersCorrectPosition(p)) + + it('does not render the tooltip if the `label` prop is empty', () => { + const text = 'Button text' + + mount(KTooltip, { + props: { + testMode: true, + trigger: 'click', + }, + slots: { + default: () => h('button', {}, 'text'), + }, + }) + + cy.get('button').click() + + cy.get('.k-tooltip').should('have.class', 'k-tooltip-hidden').and('not.be.visible') + }) }) From ddc778e77d0f54b67f11e0967511e68832b033ab Mon Sep 17 00:00:00 2001 From: Adam DeHaven Date: Fri, 20 Oct 2023 13:04:53 -0400 Subject: [PATCH 4/4] test: use var --- src/components/KTooltip/KTooltip.cy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/KTooltip/KTooltip.cy.ts b/src/components/KTooltip/KTooltip.cy.ts index 533a0e4df8..d08873c7cc 100644 --- a/src/components/KTooltip/KTooltip.cy.ts +++ b/src/components/KTooltip/KTooltip.cy.ts @@ -47,7 +47,7 @@ describe('KTooltip', () => { trigger: 'click', }, slots: { - default: () => h('button', {}, 'text'), + default: () => h('button', {}, text), }, })