File tree Expand file tree Collapse file tree 9 files changed +46
-1
lines changed Expand file tree Collapse file tree 9 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ const collection = new MaterialCollection<KnobTypesToKnobs<StoryKnobs>>(
38
38
new Knob ( 'focused' , { ui : boolInput ( ) , defaultValue : false } ) ,
39
39
new Knob ( 'populated' , { ui : boolInput ( ) , defaultValue : false } ) ,
40
40
new Knob ( 'required' , { ui : boolInput ( ) , defaultValue : false } ) ,
41
+ new Knob ( 'noAsterisk' , { ui : boolInput ( ) , defaultValue : false } ) ,
41
42
new Knob ( 'Leading icon' , { ui : boolInput ( ) , defaultValue : false } ) ,
42
43
new Knob ( 'Trailing icon' , { ui : boolInput ( ) , defaultValue : false } ) ,
43
44
new Knob ( 'resizable' , { ui : boolInput ( ) , defaultValue : false } ) ,
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export interface StoryKnobs {
22
22
focused : boolean ;
23
23
populated : boolean ;
24
24
required : boolean ;
25
+ noAsterisk : boolean ;
25
26
'Leading icon' : boolean ;
26
27
'Trailing icon' : boolean ;
27
28
resizable : boolean ;
@@ -48,6 +49,7 @@ const filled: MaterialStoryInit<StoryKnobs> = {
48
49
disabled,
49
50
error,
50
51
focused,
52
+ noAsterisk,
51
53
populated,
52
54
required,
53
55
resizable,
@@ -73,6 +75,7 @@ const filled: MaterialStoryInit<StoryKnobs> = {
73
75
.focused=${ focused }
74
76
.hasStart=${ hasStart }
75
77
.hasEnd=${ hasEnd }
78
+ .noAsterisk=${ noAsterisk }
76
79
.populated=${ populated }
77
80
.required=${ required }
78
81
supporting-text=${ supportingText }
@@ -95,6 +98,7 @@ const outlined: MaterialStoryInit<StoryKnobs> = {
95
98
disabled,
96
99
error,
97
100
focused,
101
+ noAsterisk,
98
102
populated,
99
103
required,
100
104
resizable,
@@ -122,6 +126,7 @@ const outlined: MaterialStoryInit<StoryKnobs> = {
122
126
.focused=${ focused }
123
127
.hasStart=${ hasStart }
124
128
.hasEnd=${ hasEnd }
129
+ .noAsterisk=${ noAsterisk }
125
130
.populated=${ populated }
126
131
.required=${ required }
127
132
supporting-text=${ supportingText }
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ export class Field extends LitElement {
25
25
@property ( { type : Boolean } ) error = false ;
26
26
@property ( { type : Boolean } ) focused = false ;
27
27
@property ( ) label = '' ;
28
+ @property ( { type : Boolean , attribute : 'no-asterisk' } ) noAsterisk = false ;
28
29
@property ( { type : Boolean } ) populated = false ;
29
30
@property ( { type : Boolean } ) required = false ;
30
31
@property ( { type : Boolean } ) resizable = false ;
@@ -242,7 +243,9 @@ export class Field extends LitElement {
242
243
} ;
243
244
244
245
// Add '*' if a label is present and the field is required
245
- const labelText = `${ this . label } ${ this . required ? '*' : '' } ` ;
246
+ const labelText = `${ this . label } ${
247
+ this . required && ! this . noAsterisk ? '*' : ''
248
+ } `;
246
249
247
250
return html `
248
251
< span class ="label ${ classMap ( classes ) } " aria-hidden =${ ! visible }
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ describe('Field', () => {
52
52
const template = html `
53
53
< md-test-field
54
54
.label =${ props . label ?? '' }
55
+ ?no-asterisk =${ props . noAsterisk ?? false }
55
56
?disabled=${ props . disabled ?? false }
56
57
.error=${ props . error ?? false }
57
58
.populated=${ props . populated ?? false }
@@ -334,6 +335,21 @@ describe('Field', () => {
334
335
)
335
336
. toBe ( '' ) ;
336
337
} ) ;
338
+
339
+ it ( 'should not render asterisk if required, but noAsterisk' , async ( ) => {
340
+ // Setup.
341
+ // Test case.
342
+ const labelValue = 'Label' ;
343
+ const { instance} = await setupTest ( {
344
+ required : true , label : labelValue , noAsterisk : true
345
+ } ) ;
346
+ //Assertion
347
+ expect ( instance . labelText )
348
+ . withContext (
349
+ 'label test should equal label without asterisk, when required and noAsterisk' ,
350
+ )
351
+ . toBe ( labelValue ) ;
352
+ } ) ;
337
353
} ) ;
338
354
339
355
describe ( 'supporting text' , ( ) => {
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ const collection = new MaterialCollection<KnobTypesToKnobs<StoryKnobs>>(
32
32
new Knob ( 'typeaheadDelay' , { ui : numberInput ( ) , defaultValue : 200 } ) ,
33
33
new Knob ( 'quick' , { ui : boolInput ( ) , defaultValue : false } ) ,
34
34
new Knob ( 'required' , { ui : boolInput ( ) , defaultValue : false } ) ,
35
+ new Knob ( 'noAsterisk' , { ui : boolInput ( ) , defaultValue : false } ) ,
35
36
new Knob ( 'disabled' , { ui : boolInput ( ) , defaultValue : false } ) ,
36
37
new Knob ( 'errorText' , { ui : textInput ( ) , defaultValue : '' } ) ,
37
38
new Knob ( 'supportingText' , { ui : textInput ( ) , defaultValue : '' } ) ,
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ export interface StoryKnobs {
19
19
typeaheadDelay : number ;
20
20
quick : boolean ;
21
21
required : boolean ;
22
+ noAsterisk : boolean ;
22
23
disabled : boolean ;
23
24
errorText : string ;
24
25
supportingText : string ;
@@ -41,6 +42,7 @@ const selects: MaterialStoryInit<StoryKnobs> = {
41
42
.label =${ knobs . label }
42
43
.quick =${ knobs . quick }
43
44
.required=${ knobs . required }
45
+ .noAsterisk=${ knobs . noAsterisk }
44
46
.disabled=${ knobs . disabled }
45
47
.errorText=${ knobs . errorText }
46
48
.supportingText=${ knobs . supportingText }
@@ -58,6 +60,7 @@ const selects: MaterialStoryInit<StoryKnobs> = {
58
60
.label =${ knobs . label }
59
61
.quick =${ knobs . quick }
60
62
.required=${ knobs . required }
63
+ .noAsterisk=${ knobs . noAsterisk }
61
64
.disabled=${ knobs . disabled }
62
65
.errorText=${ knobs . errorText }
63
66
.supportingText=${ knobs . supportingText }
Original file line number Diff line number Diff line change @@ -106,6 +106,12 @@ export abstract class Select extends selectBaseClass {
106
106
*/
107
107
@property ( ) label = '' ;
108
108
109
+ /**
110
+ * Disables the asterisk on the floating label, when the select is
111
+ * required.
112
+ */
113
+ @property ( { type : Boolean , attribute : 'no-asterisk' } ) noAsterisk = false ;
114
+
109
115
/**
110
116
* Conveys additional information below the select, such as how it should
111
117
* be used.
@@ -395,6 +401,7 @@ export abstract class Select extends selectBaseClass {
395
401
aria-controls="listbox"
396
402
class="field"
397
403
label=${ this . label }
404
+ ?no-asterisk=${ this . noAsterisk }
398
405
.focused=${ this . focused || this . open }
399
406
.populated=${ ! ! this . displayText }
400
407
.disabled=${ this . disabled }
Original file line number Diff line number Diff line change @@ -213,12 +213,14 @@ const forms: MaterialStoryInit<StoryKnobs> = {
213
213
label ="First name"
214
214
name="first-name"
215
215
required
216
+ no-asterisk
216
217
autocomplete="given-name"> </ md-filled-text-field >
217
218
< md-filled-text-field
218
219
?disabled =${ knobs . disabled }
219
220
label ="Last name"
220
221
name="last-name"
221
222
required
223
+ no-asterisk
222
224
autocomplete="family-name"> </ md-filled-text-field >
223
225
</ div >
224
226
< div class ="row buttons ">
Original file line number Diff line number Diff line change @@ -132,6 +132,12 @@ export abstract class TextField extends textFieldBaseClass {
132
132
*/
133
133
@property ( ) label = '' ;
134
134
135
+ /**
136
+ * Disables the asterisk on the floating label, when the text field is
137
+ * required.
138
+ */
139
+ @property ( { type : Boolean , attribute : 'no-asterisk' } ) noAsterisk = false ;
140
+
135
141
/**
136
142
* Indicates that the user must specify a value for the input before the
137
143
* owning form can be submitted and will render an error state when
@@ -554,6 +560,7 @@ export abstract class TextField extends textFieldBaseClass {
554
560
?has-end=${ this . hasTrailingIcon }
555
561
?has-start=${ this . hasLeadingIcon }
556
562
label=${ this . label }
563
+ ?no-asterisk=${ this . noAsterisk }
557
564
max=${ this . maxLength }
558
565
?populated=${ ! ! this . value }
559
566
?required=${ this . required }
You can’t perform that action at this time.
0 commit comments