Skip to content

Commit d1cc7e6

Browse files
committed
feat: add data-qa
1 parent 4608fb9 commit d1cc7e6

File tree

7 files changed

+43
-7
lines changed

7 files changed

+43
-7
lines changed

packages/components/src/components/checkbox/checkbox.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export class Checkbox {
6868
/** (optional) id or space separated list of ids of elements that provide or link to additional related information. */
6969
@Prop() ariaDetailsId?: string;
7070

71+
/** (optional) data-qa attribute for e2e testing */
72+
@Prop() dataQa?: string;
73+
7174
/** Emitted when the value has changed. */
7275
@Event({ eventName: 'scale-change' }) scaleChange: EventEmitter;
7376
/** @deprecated in v3 in favor of kebab-case event names */
@@ -196,6 +199,7 @@ export class Checkbox {
196199
disabled={this.disabled}
197200
required={this.required}
198201
onChange={this.handleChange}
202+
{...(this.dataQa ? { 'data-qa': this.dataQa } : {})}
199203
/>
200204
<label part="container" htmlFor={this.inputId}>
201205
<span part="checkbox">{this.renderIcon()}</span>

packages/components/src/components/input/input.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ export class Input {
106106
/** (optional) Injected CSS styles */
107107
@Prop() styles?: string;
108108

109+
/** (optional) data-qa attribute for e2e testing */
110+
@Prop() dataQa?: string;
111+
109112
/** Emitted when a keyboard input occurred. */
110113
@Event({ eventName: 'scale-input' }) scaleInput!: EventEmitter<KeyboardEvent>;
111114
/** @deprecated in v3 in favor of kebab-case event names */
@@ -325,6 +328,7 @@ export class Input {
325328
disabled={this.disabled}
326329
{...ariaInvalidAttr}
327330
{...ariaDescribedByAttr}
331+
{...(this.dataQa ? { 'data-qa': this.dataQa } : {})}
328332
/>
329333
<div
330334
class={classNames('input__checkbox-container')}
@@ -366,6 +370,7 @@ export class Input {
366370
disabled={this.disabled}
367371
{...ariaInvalidAttr}
368372
{...ariaDescribedByAttr}
373+
{...(this.dataQa ? { 'data-qa': this.dataQa } : {})}
369374
/>
370375
<label htmlFor={this.inputId}>{this.label}</label>
371376
{!!this.helperText && (
@@ -409,6 +414,7 @@ export class Input {
409414
size={this.visibleSize}
410415
{...ariaInvalidAttr}
411416
{...ariaDescribedByAttr}
417+
{...(this.dataQa ? { 'data-qa': this.dataQa } : {})}
412418
>
413419
<slot />
414420
</select>
@@ -439,6 +445,7 @@ export class Input {
439445
{...(!!this.cols ? { cols: this.cols } : {})}
440446
{...ariaInvalidAttr}
441447
{...ariaDescribedByAttr}
448+
{...(this.dataQa ? { 'data-qa': this.dataQa } : {})}
442449
/>
443450
)}
444451

packages/components/src/components/radio-button/radio-button.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export class RadioButton {
5656
/** (optional) id or space separated list of ids of elements that provide or link to additional related information. */
5757
@Prop() ariaDetailsId?: string;
5858

59+
/** (optional) data-qa attribute for e2e testing */
60+
@Prop() dataQa?: string;
61+
5962
@Event({ eventName: 'scale-change' })
6063
scaleChange!: EventEmitter<InputChangeEventDetail>;
6164
/** @deprecated in v3 in favor of kebab-case event names */
@@ -94,7 +97,6 @@ export class RadioButton {
9497
});
9598
}
9699
};
97-
98100
// We manually set `checked` to false on sibling <scale-radio-button> elements,
99101
// otherwise they stayed `checked` after being clicked once, forever.
100102
uncheckSiblings() {
@@ -145,6 +147,7 @@ export class RadioButton {
145147
? ariaDescribedByAttr
146148
: {})}
147149
aria-details={this.ariaDetailsId}
150+
{...(this.dataQa ? { 'data-qa': this.dataQa } : {})}
148151
/>
149152
<label htmlFor={this.inputId}>{this.label}</label>
150153
{!!this.helperText && (

packages/components/src/components/slider/slider.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export class Slider {
8989
/** (optional) Injected CSS styles */
9090
@Prop() styles?: string;
9191

92+
/** (optional) data-qa attribute for e2e testing */
93+
@Prop() dataQa?: string;
94+
9295
// The actual position in % of the slider thumb
9396
@State() position: number = 0;
9497
@State() positionFrom: number = 25;
@@ -264,7 +267,6 @@ export class Slider {
264267
this[positionKey] =
265268
((clampedValue - this.min) * 100) / (this.max - this.min);
266269
};
267-
268270
/**
269271
* Utility function
270272
* e.g. 'value' -> 'valueFrom' if `activeRangeThumb='From'`
@@ -405,6 +407,9 @@ export class Slider {
405407
aria-orientation="horizontal"
406408
aria-disabled={this.disabled}
407409
{...(this.helperText ? ariaDescribedByAttr : {})}
410+
{...(this.dataQa
411+
? { 'data-qa': `${this.dataQa}-from` }
412+
: {})}
408413
onKeyDown={this.onKeyDown}
409414
/>
410415
</div>
@@ -427,6 +432,9 @@ export class Slider {
427432
aria-orientation="horizontal"
428433
aria-disabled={this.disabled}
429434
{...(this.helperText ? ariaDescribedByAttr : {})}
435+
{...(this.dataQa
436+
? { 'data-qa': `${this.dataQa}-to` }
437+
: {})}
430438
onKeyDown={this.onKeyDown}
431439
/>
432440
</div>
@@ -451,6 +459,7 @@ export class Slider {
451459
aria-orientation="horizontal"
452460
aria-disabled={this.disabled}
453461
{...(this.helperText ? ariaDescribedByAttr : {})}
462+
{...(this.dataQa ? { 'data-qa': this.dataQa } : {})}
454463
onKeyDown={this.onKeyDown}
455464
/>
456465
</div>

packages/components/src/components/switch/switch.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export class Switch {
4040

4141
@Prop() size?: 'small' | 'large' = 'large';
4242

43+
/** (optional) data-qa attribute for e2e testing */
44+
@Prop() dataQa?: string;
45+
4346
/** Emitted when the switch was clicked */
4447
@Event({ eventName: 'scale-change' }) scaleChange!: EventEmitter;
4548
/** @deprecated in v3 in favor of kebab-case event names */
@@ -65,6 +68,7 @@ export class Switch {
6568
disabled={this.disabled}
6669
aria-labelledby={`${this.inputId}-label`}
6770
id={this.inputId}
71+
{...(this.dataQa ? { 'data-qa': this.dataQa } : {})}
6872
onChange={(event: any) => {
6973
this.checked = event.target.checked;
7074
emitEvent(this, 'scaleChange', { value: this.checked });

packages/components/src/components/text-field/text-field.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ export class TextField {
113113
@Prop() styles?: string;
114114
/** (optional)) Makes type `input` behave as a controlled component in React */
115115
@Prop() experimentalControlled?: boolean = false;
116+
117+
/** (optional) data-qa attribute for e2e testing */
118+
@Prop() dataQa?: string;
119+
116120
/** Emitted when a keyboard input occurred. */
117121
@Event({ eventName: 'scale-input' }) scaleInput!: EventEmitter<KeyboardEvent>;
118122
/** @deprecated in v3 in favor of kebab-case event names */
@@ -180,12 +184,10 @@ export class TextField {
180184
});
181185
}
182186
}
183-
184187
// We're not watching `value` like we used to
185188
// because we get unwanted `scaleChange` events
186189
// because how we keep this.value up-to-date for type="select"
187190
// `this.value = selectedValue`
188-
189191
emitChange() {
190192
emitEvent(this, 'scaleChange', {
191193
value: this.value == null ? this.value : this.value.toString(),
@@ -289,6 +291,7 @@ export class TextField {
289291
: {})}
290292
{...(this.helperText && this.ariaDetailedId ? ariaDetailsAttr : {})}
291293
{...(numericTypes.includes(this.type) ? { step: this.step } : {})}
294+
{...(this.dataQa ? { 'data-qa': this.dataQa } : {})}
292295
/>
293296
{(!!this.helperText || !!this.counter) && (
294297
<div

packages/components/src/components/textarea/textarea.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface InputChangeEventDetail {
3434
})
3535
export class Textarea {
3636
@Element() hostElement: HTMLElement;
37+
3738
/** (optional) Input name */
3839
@Prop() name?: string = '';
3940
/** (optional) Input label */
@@ -80,6 +81,9 @@ export class Textarea {
8081
/** (optional) id or space separated list of ids of elements that provide or link to additional related information. */
8182
@Prop() ariaDetailsId?: string;
8283

84+
/** (optional) data-qa attribute for e2e testing */
85+
@Prop() dataQa?: string;
86+
8387
/** Emitted when a keyboard input occurred. */
8488
@Event({ eventName: 'scale-input' }) scaleInput!: EventEmitter<KeyboardEvent>;
8589
/** @deprecated in v3 in favor of kebab-case event names */
@@ -94,11 +98,13 @@ export class Textarea {
9498
/** Emitted when the input has focus. */
9599
@Event({ eventName: 'scale-focus' }) scaleFocus!: EventEmitter<void>;
96100
/** @deprecated in v3 in favor of kebab-case event names */
97-
@Event({ eventName: 'scaleFocus' }) scaleFocusLegacy!: EventEmitter<void>;
101+
@Event({ eventName: 'scaleFocus' })
102+
scaleFocusLegacy!: EventEmitter<void>;
98103
/** Emitted when the input loses focus. */
99104
@Event({ eventName: 'scale-blur' }) scaleBlur!: EventEmitter<void>;
100105
/** @deprecated in v3 in favor of kebab-case event names */
101-
@Event({ eventName: 'scaleBlur' }) scaleBlurLegacy!: EventEmitter<void>;
106+
@Event({ eventName: 'scaleBlur' })
107+
scaleBlurLegacy!: EventEmitter<void>;
102108
/** Emitted on keydown. */
103109
@Event({ eventName: 'scale-keydown' })
104110
scaleKeyDown!: EventEmitter<KeyboardEvent>;
@@ -129,7 +135,6 @@ export class Textarea {
129135
});
130136
}
131137
}
132-
133138
// We're not watching `value` like we used to
134139
// because we get unwanted `scaleChange` events
135140
// because how we keep this.value up-to-date for type="select"
@@ -219,6 +224,7 @@ export class Textarea {
219224
? ariaDescribedByAttr
220225
: {})}
221226
aria-details={this.ariaDetailsId}
227+
{...(this.dataQa ? { 'data-qa': this.dataQa } : {})}
222228
ref={(el) => (this.focusableElement = el)}
223229
/>
224230
</div>

0 commit comments

Comments
 (0)