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(forms)!: bind $attrs to elements #279

Merged
merged 1 commit into from
Jun 13, 2023
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
16 changes: 7 additions & 9 deletions docs/components/ThemeSelect.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div class="flex items-center shadow-sm">
<ClientOnly>
<ClientOnly>
<div class="inline-flex shadow-sm rounded-md">
<USelectMenu
v-model="primary"
name="primary"
class="w-full [&>div>button]:!rounded-r-none"
class="!rounded-r-none !shadow-none focus:z-[1]"
color="gray"
:ui="{ width: 'w-[194px]' }"
:popper="{ placement: 'bottom-start' }"
Expand All @@ -22,15 +22,13 @@
{{ option.text }}
</template>
</USelectMenu>
</ClientOnly>

<ClientOnly>
<USelectMenu
v-model="gray"
name="gray"
class="w-full [&>div>button]:!rounded-l-none [&>div>button]:-ml-px"
class="!rounded-l-none !shadow-none"
color="gray"
:ui="{ width: 'w-[194px]' }"
:ui="{ width: 'w-[194px]', wrapper: '-ml-px' }"
:popper="{ placement: 'bottom-end' }"
:options="grayOptions"
>
Expand All @@ -46,8 +44,8 @@
{{ option.text }}
</template>
</USelectMenu>
</ClientOnly>
</div>
</div>
</ClientOnly>
</template>

<script setup lang="ts">
Expand Down
10 changes: 4 additions & 6 deletions docs/components/content/ComponentCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
v-model="componentProps[prop.name]"
:name="`prop-${prop.name}`"
variant="none"
class="justify-center"
:ui="{ wrapper: 'relative flex items-start justify-center' }"
/>
<USelectMenu
v-else-if="prop.type === 'string' && prop.options.length"
v-model="componentProps[prop.name]"
:options="prop.options"
:name="`prop-${prop.name}`"
:label="componentProps[prop.name]"
variant="none"
class="inline-flex"
:ui="{ width: 'w-32 !-mt-px', rounded: 'rounded-b-md' }"
:ui-select="{ custom: '!py-0' }"
:ui="{ width: 'w-32 !-mt-px', rounded: 'rounded-b-md', wrapper: 'relative inline-flex' }"
class="!py-0"
:popper="{ strategy: 'fixed', placement: 'bottom-start' }"
/>
<UInput
Expand All @@ -29,7 +27,7 @@
:name="`prop-${prop.name}`"
variant="none"
autocomplete="off"
:ui="{ custom: '!py-0' }"
class="!py-0"
@update:model-value="val => componentProps[prop.name] = prop.type === 'number' ? Number(val) : val"
/>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/runtime/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ const input = {
base: 'relative block w-full disabled:cursor-not-allowed disabled:opacity-75 focus:outline-none border-0',
rounded: 'rounded-md',
placeholder: 'placeholder-gray-400 dark:placeholder-gray-500',
custom: '',
size: {
'2xs': 'text-xs',
xs: 'text-xs',
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/components/forms/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
type="checkbox"
class="form-checkbox"
:class="[ui.base, ui.rounded, ui.custom]"
v-bind="$attrs"
@focus="$emit('focus', $event)"
@blur="$emit('blur', $event)"
>
Expand Down Expand Up @@ -41,6 +42,7 @@ import appConfig from '#build/app.config'
// const appConfig = useAppConfig()

export default defineComponent({
inheritAttrs: false,
props: {
value: {
type: [String, Number, Boolean, Object],
Expand Down
20 changes: 3 additions & 17 deletions src/runtime/components/forms/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
:required="required"
:placeholder="placeholder"
:disabled="disabled || loading"
:readonly="readonly"
:autocomplete="autocomplete"
:spellcheck="spellcheck"
class="form-input"
:class="inputClass"
v-bind="$attrs"
@input="onInput"
@focus="$emit('focus', $event)"
@blur="$emit('blur', $event)"
Expand Down Expand Up @@ -51,6 +49,7 @@ export default defineComponent({
components: {
UIcon
},
inheritAttrs: false,
props: {
modelValue: {
type: [String, Number],
Expand All @@ -76,22 +75,10 @@ export default defineComponent({
type: Boolean,
default: false
},
readonly: {
type: Boolean,
default: false
},
autofocus: {
type: Boolean,
default: false
},
autocomplete: {
type: String,
default: null
},
spellcheck: {
type: Boolean,
default: null
},
icon: {
type: String,
default: null
Expand Down Expand Up @@ -189,8 +176,7 @@ export default defineComponent({
props.padded ? ui.value.padding[props.size] : 'p-0',
variant?.replaceAll('{color}', props.color),
(isLeading.value || slots.leading) && ui.value.leading.padding[props.size],
(isTrailing.value || slots.trailing) && ui.value.trailing.padding[props.size],
ui.value.custom
(isTrailing.value || slots.trailing) && ui.value.trailing.padding[props.size]
)
})

Expand Down
2 changes: 2 additions & 0 deletions src/runtime/components/forms/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
type="radio"
class="form-radio"
:class="[ui.base, ui.custom]"
v-bind="$attrs"
@focus="$emit('focus', $event)"
@blur="$emit('blur', $event)"
>
Expand Down Expand Up @@ -39,6 +40,7 @@ import appConfig from '#build/app.config'
// const appConfig = useAppConfig()

export default defineComponent({
inheritAttrs: false,
props: {
value: {
type: [String, Number, Boolean],
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/components/forms/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:disabled="disabled || loading"
class="form-select"
:class="selectClass"
v-bind="$attrs"
@input="onInput"
>
<template v-for="(option, index) in normalizedOptionsWithPlaceholder">
Expand Down Expand Up @@ -69,6 +70,7 @@ export default defineComponent({
components: {
UIcon
},
inheritAttrs: false,
props: {
modelValue: {
type: [String, Number, Object],
Expand Down Expand Up @@ -236,8 +238,7 @@ export default defineComponent({
props.padded ? ui.value.padding[props.size] : 'p-0',
variant?.replaceAll('{color}', props.color),
(isLeading.value || slots.leading) && ui.value.leading.padding[props.size],
(isTrailing.value || slots.trailing) && ui.value.trailing.padding[props.size],
ui.value.custom
(isTrailing.value || slots.trailing) && ui.value.trailing.padding[props.size]
)
})

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/components/forms/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class="inline-flex w-full"
>
<slot :open="open" :disabled="disabled" :loading="loading">
<button :class="selectMenuClass" :disabled="disabled || loading" type="button">
<button :class="selectMenuClass" :disabled="disabled || loading" type="button" v-bind="$attrs">
<span v-if="(isLeading && leadingIconName) || $slots.leading" :class="leadingWrapperIconClass">
<slot name="leading" :disabled="disabled" :loading="loading">
<UIcon :name="leadingIconName" :class="leadingIconClass" />
Expand Down Expand Up @@ -146,6 +146,7 @@ export default defineComponent({
UIcon,
UAvatar
},
inheritAttrs: false,
props: {
modelValue: {
type: [String, Number, Object, Array],
Expand Down Expand Up @@ -300,7 +301,6 @@ export default defineComponent({
variant?.replaceAll('{color}', props.color),
(isLeading.value || slots.leading) && uiSelect.value.leading.padding[props.size],
(isTrailing.value || slots.trailing) && uiSelect.value.trailing.padding[props.size],
uiSelect.value.custom,
'inline-flex items-center'
)
})
Expand Down
10 changes: 3 additions & 7 deletions src/runtime/components/forms/Textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
:required="required"
:disabled="disabled"
:placeholder="placeholder"
:autocomplete="autocomplete"
class="form-textarea"
:class="textareaClass"
v-bind="$attrs"
@input="onInput"
@focus="$emit('focus', $event)"
@blur="$emit('blur', $event)"
Expand All @@ -32,6 +32,7 @@ import appConfig from '#build/app.config'
// const appConfig = useAppConfig()

export default defineComponent({
inheritAttrs: false,
props: {
modelValue: {
type: [String, Number],
Expand Down Expand Up @@ -65,10 +66,6 @@ export default defineComponent({
type: Boolean,
default: false
},
autocomplete: {
type: String,
default: null
},
resize: {
type: Boolean,
default: false
Expand Down Expand Up @@ -170,8 +167,7 @@ export default defineComponent({
ui.value.size[props.size],
props.padded ? ui.value.padding[props.size] : 'p-0',
variant?.replaceAll('{color}', props.color),
!props.resize && 'resize-none',
ui.value.custom
!props.resize && 'resize-none'
)
})

Expand Down