Skip to content

Commit ea895ed

Browse files
committed
refactor(radio-group): requested changes
1 parent d1db2fc commit ea895ed

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

src/components/radio-group/radio-group.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ export default class IgcRadioGroupComponent extends LitElement {
3131
private _name!: string;
3232
private _value!: string;
3333

34-
@property({ type: Boolean, reflect: true })
35-
private disabled = false;
36-
37-
@property({ type: Boolean, reflect: true })
38-
private labelBefore = false;
39-
40-
@queryAssignedElements({ flatten: true })
34+
@queryAssignedElements({ selector: 'igc-radio', flatten: true })
4135
private _radios!: NodeListOf<IgcRadioComponent>;
4236

4337
/**
@@ -93,12 +87,20 @@ export default class IgcRadioGroupComponent extends LitElement {
9387
}
9488

9589
private _observerCallback() {
96-
const radios = Array.from(this._radios as unknown as Element[]).filter(
97-
(el) => el.tagName.toLowerCase() === 'igc-radio'
98-
) as IgcRadioComponent[];
99-
this.disabled = radios.every((radio) => radio.disabled);
100-
this.labelBefore =
101-
radios.some((radio) => radio.labelPosition === 'before') ?? false;
90+
const radios = Array.from(this._radios);
91+
const setState = (state: string, condition: boolean) =>
92+
condition
93+
? this._internals.states.add(state)
94+
: this._internals.states.delete(state);
95+
96+
setState(
97+
'disabled',
98+
radios.every((radio) => radio.disabled)
99+
);
100+
setState(
101+
'labelBefore',
102+
radios.some((radio) => radio.labelPosition === 'before')
103+
);
102104
}
103105

104106
constructor() {

src/components/radio-group/themes/radio-group.base.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
flex-direction: column;
1313
gap: rem(8px);
1414
width: max-content;
15+
16+
::slotted(label) {
17+
margin-block-end: rem(8px);
18+
}
1519
}
1620

17-
:host([alignment='vertical'][labelBefore]) {
21+
:host(:state(labelBefore)[alignment='vertical']) {
1822
::slotted(*) {
1923
align-self: flex-end;
2024
}

src/components/radio-group/themes/shared/radio-group.common.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ $theme: $material;
55

66
:host {
77
::slotted(label) {
8-
margin-block-end: rem(16px);
98
color: var-get($theme, 'color');
109
}
1110
}
1211

13-
:host([disabled]) {
12+
:host(:state(disabled)) {
1413
::slotted(label) {
1514
color: var-get($theme, 'disabled-color');
1615
}
17-
}
16+
}

src/components/radio-group/themes/shared/radio-group.material.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
:host([alignment='vertical']) {
1212
gap: 0;
13+
14+
::slotted(label) {
15+
margin-block-end: rem(16px);
16+
}
1317
}
1418

1519
:host([alignment='horizontal']) {

0 commit comments

Comments
 (0)