Skip to content

Commit

Permalink
fix(kinputswitch): add tooltipattributes prop (#2613)
Browse files Browse the repository at this point in the history
* fix(kinputswitch): add tooltipattributes prop

* fix: address pr feedback
  • Loading branch information
portikM authored Feb 12, 2025
1 parent 490ee94 commit 89c8ff9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/components/input-switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Use this prop to display tooltip text when KInputSwitch is disabled.
<KInputSwitch disabled disabled-tooltip-text="Scale down this cluster first to enable editing" v-model="switchValue" />
```

### tooltipAttributes

Use the `tooltipAttributes` prop to configure the KTooltip's [props](/components/tooltip) when using the `disabledTooltipText` prop.

### HTML Attributes

#### disabled
Expand Down
3 changes: 2 additions & 1 deletion sandbox/pages/SandboxInputSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@
label="Disabled"
/>
</SandboxSectionComponent>
<SandboxSectionComponent title="disabledTooltipText">
<SandboxSectionComponent title="disabledTooltipText & tooltipAttributes">
<KInputSwitch
v-model="vModel1"
disabled
disabled-tooltip-text="Disabled tooltip text"
label="Disabled"
:tooltip-attributes="{ placement: 'bottom-start' }"
/>
</SandboxSectionComponent>

Expand Down
13 changes: 9 additions & 4 deletions src/components/KInputSwitch/KInputSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
type="checkbox"
@input="handleChange"
>
<component
:is="disabled && disabledTooltipText ? 'KTooltip' : 'div'"
<KTooltip
v-bind="disabled && disabledTooltipText ? tooltipAttributes : {}"
class="switch-control-wrapper"
:label="disabledTooltipText"
:text="disabled ? disabledTooltipText : ''"
>
<span
:aria-checked="modelValue"
Expand All @@ -34,7 +34,7 @@
<!-- white vertical bar that is visible when switch is enabled -->
<span class="switch-control-enabled-bar" />
</span>
</component>
</KTooltip>

<KLabel
v-if="label || $slots.label"
Expand All @@ -50,6 +50,7 @@
<script lang="ts" setup>
import type { PropType } from 'vue'
import { computed, ref, useAttrs, useId } from 'vue'
import type { TooltipAttributes } from '@/types'
const props = defineProps({
/**
Expand Down Expand Up @@ -80,6 +81,10 @@ const props = defineProps({
type: String,
default: '',
},
tooltipAttributes: {
type: Object as PropType<TooltipAttributes>,
default: () => ({}),
},
/**
* Whether the label should be placed before the switch
*/
Expand Down

0 comments on commit 89c8ff9

Please sign in to comment.