File tree 2 files changed +19
-1
lines changed 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export let placeholder = ''
10
10
export let maxlength = undefined
11
11
export let autofocus = false
12
12
export let disabled = false
13
+ export let required = false
13
14
14
15
const labelID = generateRandomID (' text-label-' )
15
16
@@ -26,6 +27,15 @@ onMount(() => {
26
27
const focus = (node ) => autofocus && node .focus ()
27
28
</script >
28
29
30
+ <style >
31
+ .required {
32
+ color : #da1414 ;
33
+ font-size : small ;
34
+ margin-left : 1rem ;
35
+ margin-top : 0.2rem ;
36
+ }
37
+ </style >
38
+
29
39
<label
30
40
class ="mdc-text-field mdc-text-field--outlined {$$props .class } textfield-radius"
31
41
class:mdc-text-field--no-label ={! label }
@@ -42,6 +52,7 @@ const focus = (node) => autofocus && node.focus()
42
52
on:keydown
43
53
on:keypress
44
54
on:keyup
55
+ {required }
45
56
{maxlength }
46
57
{disabled }
47
58
{placeholder }
@@ -50,9 +61,14 @@ const focus = (node) => autofocus && node.focus()
50
61
<span class =" mdc-notched-outline__leading" />
51
62
{#if label }
52
63
<span class =" mdc-notched-outline__notch" >
53
- <span class ="mdc-floating-label" id ={labelID }>{label }</span >
64
+ <span class ="mdc-floating-label" id ={labelID }>
65
+ {label }
66
+ </span >
54
67
</span >
55
68
{/if }
56
69
<span class =" mdc-notched-outline__trailing" />
57
70
</span >
58
71
</label >
72
+ {#if required && ! value }
73
+ <div class =" required" >*Required</div >
74
+ {/if }
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ let lastKey = ''
27
27
28
28
<Story name ="Default" {args } />
29
29
30
+ <Story name ="Required" args ={copyAndModifyArgs (args , { required: true })} />
31
+
30
32
<Story name ="Placeholder" args ={copyAndModifyArgs (args , { placeholder: ' Enter text here' })} />
31
33
32
34
<Story name ="Autofocus" args ={copyAndModifyArgs (args , { autofocus: true })} />
You can’t perform that action at this time.
0 commit comments