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: do not apply extra styles when non-headless #4393

Merged
merged 3 commits into from
Oct 15, 2024
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
136 changes: 61 additions & 75 deletions packages/ui/src/components/va-button-dropdown/VaButtonDropdown.vue
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
<template>
<div class="va-button-dropdown" :class="computedClass">
<va-dropdown
v-if="!$props.split"
v-bind="vaDropdownProps"
v-model="valueComputed"
:disabled="$props.disabled || $props.disableDropdown"
:class="['va-button-dropdown']"
>
<template #anchor>
<va-button
:aria-label="tp($props.ariaLabel)"
v-bind="{ ...computedButtonIcons, ...buttonPropsComputed }"
v-on="listeners"
>
<slot name="label">
{{ label }}
</slot>
</va-button>
</template>

<slot name="content">
<va-dropdown-content>
<slot />
</va-dropdown-content>
</slot>
</va-dropdown>

<va-button-group
v-else
v-bind="buttonPropsComputed"
:class="['va-button-dropdown', 'va-button-dropdown--split']"
>
<va-button
v-if="!$props.leftIcon"
:disabled="$props.disabled || $props.disableButton"
v-bind="computedMainButtonProps"
v-on="mainButtonListeners"
>
<slot name="label">
{{ label }}
</slot>
</va-button>

<va-dropdown
v-if="!$props.split"
v-bind="vaDropdownProps"
v-model="valueComputed"
:disabled="$props.disabled || $props.disableDropdown"
>
<template #anchor>
<va-button
:aria-label="tp($props.ariaLabel)"
v-bind="{ ...computedButtonIcons, ...buttonPropsComputed }"
:aria-label="$props.ariaLabel || t('toggleDropdown')"
:disabled="$props.disabled || $props.disableDropdown"
:icon="computedIcon"
:icon-color="$props.iconColor"
v-on="listeners"
>
<slot name="label">
{{ label }}
</slot>
</va-button>
@keydown.esc.prevent="hideDropdown"
/>
</template>

<slot name="content">
<va-dropdown-content>
<slot />
</va-dropdown-content>
</slot>
<va-dropdown-content>
<slot />
</va-dropdown-content>
</va-dropdown>

<va-button-group
v-else
v-bind="buttonPropsComputed"
<va-button
v-if="$props.leftIcon"
:disabled="$props.disabled || $props.disableButton"
v-bind="computedMainButtonProps"
v-on="mainButtonListeners"
>
<va-button
v-if="!$props.leftIcon"
:disabled="$props.disabled || $props.disableButton"
v-bind="computedMainButtonProps"
v-on="mainButtonListeners"
>
<slot name="label">
{{ label }}
</slot>
</va-button>

<va-dropdown
v-bind="vaDropdownProps"
v-model="valueComputed"
:disabled="$props.disabled || $props.disableDropdown"
>
<template #anchor>
<va-button
:aria-label="$props.ariaLabel || t('toggleDropdown')"
:disabled="$props.disabled || $props.disableDropdown"
:icon="computedIcon"
:icon-color="$props.iconColor"
v-on="listeners"
@keydown.esc.prevent="hideDropdown"
/>
</template>
<va-dropdown-content>
<slot />
</va-dropdown-content>
</va-dropdown>

<va-button
v-if="$props.leftIcon"
:disabled="$props.disabled || $props.disableButton"
v-bind="computedMainButtonProps"
v-on="mainButtonListeners"
>
<slot name="label">
{{ label }}
</slot>
</va-button>
</va-button-group>
</div>
<slot name="label">
{{ label }}
</slot>
</va-button>
</va-button-group>
</template>

<script lang="ts">
Expand Down Expand Up @@ -146,10 +146,6 @@ const { valueComputed } = useStateful(props, emit)

const computedIcon = computed(() => valueComputed.value ? props.openedIcon : props.icon)

const computedClass = useBem('va-button-dropdown', () => ({
split: props.split,
}))

const slots = useSlots()

const computedButtonIcons = computed(() => {
Expand Down Expand Up @@ -207,18 +203,8 @@ defineExpose({
@import '../../styles/resources';

.va-button-dropdown {
display: inline-block;
font-family: var(--va-font-family);
vertical-align: middle;

.va-button {
margin: var(--va-button-dropdown-button-margin);
}

&--split {
.va-button {
@include keyboard-focus-outline($offset: -2px);
}
}
}
</style>
17 changes: 17 additions & 0 deletions packages/ui/src/components/va-dropdown/VaDropdown.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,20 @@ export const ScopedAttr = () => ({
components: { DropdownScopedAttr },
template: '<DropdownScopedAttr/>',
})

export const Multiroot = () => ({
components: { VaDropdown, VaDropdownContent },
template: `
<VaDropdown>
<template #anchor>
<div>First root</div>
<div>Second root</div>
</template>
<VaDropdownContent>
<div style="height: 600px; width: 100px;">
Content
</div>
</VaDropdownContent>
</VaDropdown>
`,
})
14 changes: 7 additions & 7 deletions packages/ui/src/components/va-dropdown/VaDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ export default defineComponent({
@import 'variables';

.va-dropdown {
/* Solved the alignment problem (if we try to align inline and block elements) */
line-height: var(--va-dropdown-line-height);
font-family: var(--va-font-family);
display: var(--va-dropdown-display);
position: relative;
max-width: 100%;
vertical-align: middle;
&.va-headless-wrapper {
/* Solved the alignment problem (if we try to align inline and block elements) */
line-height: var(--va-dropdown-line-height);
display: var(--va-dropdown-display);
max-width: 100%;
vertical-align: middle;
}

&--disabled {
@include va-disabled;
Expand Down
7 changes: 5 additions & 2 deletions packages/ui/src/utils/headless.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VNode, h, Teleport, Suspense, Comment, Fragment, Text, Slot } from 'vue'
import { VNode, h, Teleport, Suspense, Comment, Fragment, Text, Slot, normalizeClass } from 'vue'

type NodeAttributes = Record<string, any>

Expand Down Expand Up @@ -63,7 +63,10 @@ export const renderSlotNode = (slot: Slot | undefined, slotBind: any = {}, nodeA
if (nonCommentChildren.length === 0) { return null }
if (nonCommentChildren.length === 1) { return toNode(nonCommentChildren[0], nodeAttributes) }

return h('div', nodeAttributes, children)
return h('div', {
...nodeAttributes,
class: normalizeClass([nodeAttributes.class, 'va-headless-wrapper']),
}, children)
}

export const renderSlotNodes = (slot: Slot | undefined, slotBind: any = {}, nodeAttributes: NodeAttributes = {}) => {
Expand Down
Loading