Skip to content

Commit

Permalink
feat(v-input): use id or name for label for
Browse files Browse the repository at this point in the history
  • Loading branch information
gravitano committed May 10, 2022
1 parent 715c0d1 commit 3003dfe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/input/src/VInput.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ Default.parameters = {
},
};

export const Label = Template.bind({});
Label.args = {
label: 'Name',
id: 'name',
};
Label.parameters = {
docs: {
source: {
code: `<v-input label="Name" id="name" />`,
},
},
};

export const Email = Template.bind({});
Email.args = {
type: 'email',
Expand Down
8 changes: 6 additions & 2 deletions packages/input/src/VInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ const props = defineProps({
type: [Object, String],
default: null,
},
id: {
type: String,
default: '',
},
});
const {type, readonly, disabled, placeholder, prependIcon, appendIcon} =
Expand Down Expand Up @@ -132,7 +136,7 @@ const inputVariantClass = computed(() => {

<template>
<div class="mb-4">
<label v-if="label" :for="name" class="mb-1 block">{{ label }}</label>
<label v-if="label" :for="id || name" class="mb-1 block">{{ label }}</label>
<div v-if="text" v-bind="$attrs">{{ inputValue }}</div>
<div v-else class="relative w-full flex gap-2 items-center">
<slot name="prepend.outer">
Expand All @@ -154,7 +158,7 @@ const inputVariantClass = computed(() => {
</div>
</slot>
<input
:id="name"
:id="id || name"
v-model="inputValue"
class="
w-full
Expand Down

0 comments on commit 3003dfe

Please sign in to comment.