mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 01:52:19 +08:00
Merge branch 'ROU-11112-toggle' into ROU-11112
This commit is contained in:
4
core/src/components.d.ts
vendored
4
core/src/components.d.ts
vendored
@ -3293,7 +3293,7 @@ export namespace Components {
|
|||||||
*/
|
*/
|
||||||
"name": string;
|
"name": string;
|
||||||
/**
|
/**
|
||||||
* If `true`, the user must fill in a value before submitting a form.
|
* 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.
|
||||||
*/
|
*/
|
||||||
"required": boolean;
|
"required": boolean;
|
||||||
/**
|
/**
|
||||||
@ -8184,7 +8184,7 @@ declare namespace LocalJSX {
|
|||||||
*/
|
*/
|
||||||
"onIonFocus"?: (event: IonToggleCustomEvent<void>) => void;
|
"onIonFocus"?: (event: IonToggleCustomEvent<void>) => void;
|
||||||
/**
|
/**
|
||||||
* If `true`, the user must fill in a value before submitting a form.
|
* 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.
|
||||||
*/
|
*/
|
||||||
"required"?: boolean;
|
"required"?: boolean;
|
||||||
/**
|
/**
|
||||||
|
@ -75,3 +75,33 @@ describe('ion-toggle: disabled', () => {
|
|||||||
expect(toggle.checked).toBe(false);
|
expect(toggle.checked).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ion-toggle: required', () => {
|
||||||
|
it('should have a required attribute in inner input when true', async () => {
|
||||||
|
const page = await newSpecPage({
|
||||||
|
components: [Toggle],
|
||||||
|
html: `
|
||||||
|
<ion-toggle required="true">Toggle</ion-toggle>
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
|
||||||
|
const toggle = page.body.querySelector('ion-toggle')!;
|
||||||
|
const nativeInput = toggle.shadowRoot?.querySelector('input[role=switch]')!;
|
||||||
|
|
||||||
|
expect(nativeInput.hasAttribute('required')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not have a required attribute in inner input when false', async () => {
|
||||||
|
const page = await newSpecPage({
|
||||||
|
components: [Toggle],
|
||||||
|
html: `
|
||||||
|
<ion-toggle required="false">Toggle</ion-toggle>
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
|
||||||
|
const toggle = page.body.querySelector('ion-toggle')!;
|
||||||
|
const nativeInput = toggle.shadowRoot?.querySelector('input[role=switch]')!;
|
||||||
|
|
||||||
|
expect(nativeInput.hasAttribute('required')).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -109,7 +109,9 @@ export class Toggle implements ComponentInterface {
|
|||||||
@Prop() alignment?: 'start' | 'center';
|
@Prop() alignment?: 'start' | 'center';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If `true`, the user must fill in a value before submitting a form.
|
* 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.
|
||||||
*/
|
*/
|
||||||
@Prop() required = false;
|
@Prop() required = false;
|
||||||
|
|
||||||
@ -295,7 +297,8 @@ export class Toggle implements ComponentInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { activated, color, checked, disabled, el, justify, labelPlacement, inputId, name, alignment, required } = this;
|
const { activated, color, checked, disabled, el, justify, labelPlacement, inputId, name, alignment, required } =
|
||||||
|
this;
|
||||||
|
|
||||||
const mode = getIonMode(this);
|
const mode = getIonMode(this);
|
||||||
const value = this.getValue();
|
const value = this.getValue();
|
||||||
|
@ -1027,10 +1027,6 @@ export const IonToggle = /*@__PURE__*/ defineContainer<JSX.IonToggle, JSX.IonTog
|
|||||||
'ionChange',
|
'ionChange',
|
||||||
'ionFocus',
|
'ionFocus',
|
||||||
'ionBlur'
|
'ionBlur'
|
||||||
], [
|
|
||||||
'ionChange',
|
|
||||||
'ionFocus',
|
|
||||||
'ionBlur'
|
|
||||||
],
|
],
|
||||||
'checked', 'ion-change');
|
'checked', 'ion-change');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user