File tree 4 files changed +22
-5
lines changed
4 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ export let width = '280px'
15
15
export let disabled = false
16
16
/** @type {string} The ID of the selected option. */
17
17
export let selectedID = ' '
18
+ /** @type {boolean} makes a selection required and adds invalid class when none selected */
19
+ export let required = false
18
20
19
21
const dispatch = createEventDispatcher ()
20
22
const labelID = generateRandomID (' select-label-' )
@@ -61,8 +63,18 @@ afterUpdate(() => {
61
63
})
62
64
</script >
63
65
64
- <div class ="mdc-select mdc-select--outlined {$$props .class || ' ' }" bind:this ={element } style ="width: {width }" >
65
- <div class ="mdc-select__anchor" role ="button" aria-haspopup ="listbox" aria-labelledby =" {labelID } {selectedTextID }" >
66
+ <div
67
+ class ="mdc-select mdc-select--outlined {$$props .class || ' ' }"
68
+ class:mdc-select--required ={required }
69
+ bind:this ={element }
70
+ style ="width: {width }"
71
+ >
72
+ <div
73
+ class =" mdc-select__anchor"
74
+ aria-required ={required }
75
+ aria-haspopup =" listbox"
76
+ aria-labelledby =" {labelID } {selectedTextID }"
77
+ >
66
78
<span class =" mdc-notched-outline" >
67
79
<span class =" mdc-notched-outline__leading" />
68
80
<span class =" mdc-notched-outline__notch" >
Original file line number Diff line number Diff line change 4
4
@use ' @material/select/styles' ;
5
5
6
6
/* MDC select floating label */
7
- .mdc-select :not (.mdc-select--disabled ).mdc-select--focused .mdc-floating-label {
7
+ .mdc-select :not (.mdc-select--disabled , .mdc-select--invalid ).mdc-select--focused .mdc-floating-label {
8
8
color : var (--mdc-theme-primary );
9
9
}
Original file line number Diff line number Diff line change @@ -235,11 +235,12 @@ declare module '@silintl/ui-components' {
235
235
}
236
236
237
237
interface SelectProps {
238
+ disabled ?: boolean
238
239
label ?: string
239
240
options ?: { name : string ; id : string } [ ]
240
- width ?: string
241
- disabled ?: boolean
241
+ required ?: boolean
242
242
selectedID ?: string
243
+ width ?: string
243
244
class ?: string
244
245
}
245
246
export class Select extends SvelteComponentTyped < SelectProps > { }
Original file line number Diff line number Diff line change @@ -26,8 +26,12 @@ const args = {
26
26
27
27
<Story name ="Default" {args } />
28
28
29
+ <Story name ="selectedID" args ={copyAndModifyArgs (args , { selectedID: ' 5' })} />
30
+
29
31
<Story name ="Label" args ={copyAndModifyArgs (args , { label: ' Label' })} />
30
32
31
33
<Story name ="Width" args ={copyAndModifyArgs (args , { width: ' 560px' })} />
32
34
33
35
<Story name ="Disabled" args ={copyAndModifyArgs (args , { disabled: true })} />
36
+
37
+ <Story name ="required" args ={copyAndModifyArgs (args , { required: true })} />
You can’t perform that action at this time.
0 commit comments