Skip to content

Commit

Permalink
Place listener under the property
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenTeaCake committed Apr 10, 2024
1 parent e5cd93a commit 1351719
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/components/switch/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export class Switch {
*/
@Prop({ reflect: true }) public label!: string;

@Watch('label')
protected validateLabelChange(newLabelValue: string) {
this.validateLabel(newLabelValue);
}

/**
* The reflective property that allows to control the state of the switch.
*
Expand Down Expand Up @@ -80,11 +85,6 @@ export class Switch {
);
}

@Watch('label')
protected validateLabelChange(newLabelValue: string) {
this.validateLabel(newLabelValue);
}

private validateLabel(labelValue: string) {
if (typeof labelValue !== 'string' || labelValue === '') {
throw new Error('Switch has no label.');
Expand Down

0 comments on commit 1351719

Please sign in to comment.