Skip to content
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

fix(kinputswitch): add tooltipattributes prop #2613

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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