Skip to content

Commit e3af985

Browse files
feat: add runtime validation for static color
1 parent 1c40f78 commit e3af985

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

second-gen/packages/core/components/divider/Divider.base.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { property } from 'lit/decorators.js';
1515

1616
import { SizedMixin, SpectrumElement } from '@swc/core/shared/base';
1717

18-
import { DIVIDER_VALID_SIZES } from './Divider.consts';
18+
import { DIVIDER_STATIC_COLORS, DIVIDER_VALID_SIZES } from './Divider.consts';
1919
import type { DividerStaticColor } from './Divider.types';
2020

2121
/**
@@ -35,7 +35,23 @@ export abstract class DividerBase extends SizedMixin(SpectrumElement, {
3535
* The static color variant to use for the divider.
3636
*/
3737
@property({ reflect: true, attribute: 'static-color' })
38-
public staticColor?: DividerStaticColor;
38+
public get staticColor(): DividerStaticColor | undefined {
39+
return this._staticColor;
40+
}
41+
42+
public set staticColor(value: DividerStaticColor | undefined) {
43+
if (
44+
value != null &&
45+
!(DIVIDER_STATIC_COLORS as readonly string[]).includes(value)
46+
) {
47+
// Silently ignore invalid values
48+
this._staticColor = undefined;
49+
return;
50+
}
51+
this._staticColor = value;
52+
}
53+
54+
private _staticColor?: DividerStaticColor;
3955

4056
protected override firstUpdated(changed: PropertyValues<this>): void {
4157
super.firstUpdated(changed);

0 commit comments

Comments
 (0)