Skip to content

Commit f104a18

Browse files
authored
Merge pull request #324 from dnum-mi/feat/dsfr-input-required
feat: ✨ Ajoute la props required sur le composant DsfrInput
2 parents 8598190 + 67d2835 commit f104a18

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/components/DsfrInput/DsfrInput.stories.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,39 @@ LabelVisible.args = {
148148
disabled: false,
149149
}
150150

151+
export const ChampObligatoire = (args) => ({
152+
components: {
153+
DsfrInput,
154+
},
155+
data () {
156+
return {
157+
...args,
158+
}
159+
},
160+
template: `
161+
<DsfrInput
162+
:model-value="modelValue"
163+
:label="label"
164+
:label-visible="labelVisible"
165+
:placeholder="placeholder"
166+
:disabled="disabled"
167+
:required="true"
168+
/>
169+
`,
170+
mounted () {
171+
document.body.parentElement.setAttribute('data-fr-theme', this.dark ? 'dark' : 'light')
172+
},
173+
})
174+
ChampObligatoire.args = {
175+
dark: false,
176+
label: 'Label champ de saisie',
177+
labelVisible: true,
178+
placeholder: 'Placeholder',
179+
modelValue: '',
180+
disabled: false,
181+
isTextarea: true,
182+
}
183+
151184
export const ChampEnErreur = (args) => ({
152185
components: {
153186
DsfrInput,

src/components/DsfrInput/DsfrInput.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { getRandomId } from '../../utils/random-utils.js'
55
66
export default defineComponent({
77
name: 'DsfrInput',
8+
89
inheritAttrs: false,
10+
911
props: {
1012
id: {
1113
type: String,
@@ -39,7 +41,9 @@ export default defineComponent({
3941
isValid: Boolean,
4042
isTextarea: Boolean,
4143
},
44+
4245
emits: ['update:modelValue'],
46+
4347
computed: {
4448
isComponent () {
4549
return this.isTextarea ? 'textarea' : 'input'
@@ -59,12 +63,22 @@ export default defineComponent({
5963
}"
6064
:for="id"
6165
>
62-
{{ label }} {{ $attrs.required ? '*' : '' }}
66+
{{ label }}
67+
68+
<!-- @slot Slot pour indiquer que le champ est obligatoire. Par défaut, met une astérisque (dans un `<span class="required">`) -->
69+
<slot name="required-tip">
70+
<span
71+
v-if="$attrs.required"
72+
class="required"
73+
>&nbsp;*</span>
74+
</slot>
75+
6376
<span
6477
v-if="hint"
6578
class="fr-hint-text"
6679
>{{ hint }}</span>
6780
</label>
81+
6882
<component
6983
:is="isComponent"
7084
v-if="!wrapper"
@@ -80,6 +94,7 @@ export default defineComponent({
8094
@input="$emit('update:modelValue', $event.target.value)"
8195
@keydown.esc="$emit('update:modelValue', '')"
8296
/>
97+
8398
<div
8499
v-else
85100
:class="[

0 commit comments

Comments
 (0)