Skip to content

Commit 6d5592e

Browse files
Merge branch 'ROU-11112-toggle' into ROU-11112
2 parents f94bcad + e8971df commit 6d5592e

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

core/src/components.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3293,7 +3293,7 @@ export namespace Components {
32933293
*/
32943294
"name": string;
32953295
/**
3296-
* If `true`, the user must fill in a value before submitting a form.
3296+
* If true, screen readers will announce it as a required field. This property works only for accessibility purposes, it will not prevent the form from submitting if the value is invalid.
32973297
*/
32983298
"required": boolean;
32993299
/**
@@ -8184,7 +8184,7 @@ declare namespace LocalJSX {
81848184
*/
81858185
"onIonFocus"?: (event: IonToggleCustomEvent<void>) => void;
81868186
/**
8187-
* If `true`, the user must fill in a value before submitting a form.
8187+
* If true, screen readers will announce it as a required field. This property works only for accessibility purposes, it will not prevent the form from submitting if the value is invalid.
81888188
*/
81898189
"required"?: boolean;
81908190
/**

core/src/components/toggle/test/toggle.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,33 @@ describe('ion-toggle: disabled', () => {
7575
expect(toggle.checked).toBe(false);
7676
});
7777
});
78+
79+
describe('ion-toggle: required', () => {
80+
it('should have a required attribute in inner input when true', async () => {
81+
const page = await newSpecPage({
82+
components: [Toggle],
83+
html: `
84+
<ion-toggle required="true">Toggle</ion-toggle>
85+
`,
86+
});
87+
88+
const toggle = page.body.querySelector('ion-toggle')!;
89+
const nativeInput = toggle.shadowRoot?.querySelector('input[role=switch]')!;
90+
91+
expect(nativeInput.hasAttribute('required')).toBeTruthy();
92+
});
93+
94+
it('should not have a required attribute in inner input when false', async () => {
95+
const page = await newSpecPage({
96+
components: [Toggle],
97+
html: `
98+
<ion-toggle required="false">Toggle</ion-toggle>
99+
`,
100+
});
101+
102+
const toggle = page.body.querySelector('ion-toggle')!;
103+
const nativeInput = toggle.shadowRoot?.querySelector('input[role=switch]')!;
104+
105+
expect(nativeInput.hasAttribute('required')).toBeFalsy();
106+
});
107+
});

core/src/components/toggle/toggle.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ export class Toggle implements ComponentInterface {
109109
@Prop() alignment?: 'start' | 'center';
110110

111111
/**
112-
* If `true`, the user must fill in a value before submitting a form.
112+
* If true, screen readers will announce it as a required field. This property
113+
* works only for accessibility purposes, it will not prevent the form from
114+
* submitting if the value is invalid.
113115
*/
114116
@Prop() required = false;
115117

@@ -295,7 +297,8 @@ export class Toggle implements ComponentInterface {
295297
}
296298

297299
render() {
298-
const { activated, color, checked, disabled, el, justify, labelPlacement, inputId, name, alignment, required } = this;
300+
const { activated, color, checked, disabled, el, justify, labelPlacement, inputId, name, alignment, required } =
301+
this;
299302

300303
const mode = getIonMode(this);
301304
const value = this.getValue();

packages/vue/src/proxies.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,10 +1027,6 @@ export const IonToggle = /*@__PURE__*/ defineContainer<JSX.IonToggle, JSX.IonTog
10271027
'ionChange',
10281028
'ionFocus',
10291029
'ionBlur'
1030-
], [
1031-
'ionChange',
1032-
'ionFocus',
1033-
'ionBlur'
10341030
],
10351031
'checked', 'ion-change');
10361032

0 commit comments

Comments
 (0)