feat(toggle): add required prop

This commit is contained in:
giuliana
2025-01-23 11:46:53 +00:00
parent 3f24a126bf
commit 3bc976b8c6

View File

@@ -108,6 +108,11 @@ export class Toggle implements ComponentInterface {
*/
@Prop() alignment?: 'start' | 'center';
/**
* If `true`, the user must fill in a value before submitting a form.
*/
@Prop() required = false;
/**
* Emitted when the user switches the toggle on or off.
*
@@ -290,7 +295,7 @@ export class Toggle implements ComponentInterface {
}
render() {
const { activated, color, checked, disabled, el, justify, labelPlacement, inputId, name, alignment } = this;
const { activated, color, checked, disabled, el, justify, labelPlacement, inputId, name, alignment, required } = this;
const mode = getIonMode(this);
const value = this.getValue();
@@ -327,6 +332,7 @@ export class Toggle implements ComponentInterface {
onFocus={() => this.onFocus()}
onBlur={() => this.onBlur()}
ref={(focusEl) => (this.focusEl = focusEl)}
required={required}
{...this.inheritedAttributes}
/>
<div