Skip to content

Commit

Permalink
fix(radio-group): treat cds-radio-panel like cds
Browse files Browse the repository at this point in the history
fixes vmware-clarity#42

Signed-off-by: Ashley Ryan <asryan@vmware.com>
  • Loading branch information
Ashley Ryan committed Apr 21, 2022
1 parent afcdef6 commit 07baca7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions projects/core/src/radio/radio-group.element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,60 @@ describe('cds-radio-group', () => {

component = element.querySelector<CdsRadioGroup>('cds-radio-group');

await componentIsStable(component);
const radio1 = component.querySelectorAll('cds-radio')[0];
const radio2 = component.querySelectorAll('cds-radio')[1];
expect(radio1.inputControl.name).toBe(radio2.inputControl.name);
expect(radio1.inputControl.name).toEqual('my-radio');
});

describe('should sync radio-panel controls within a group', async () => {
element = await createTestElement(html`
<cds-radio-group>
<label>radio group</label>
<cds-radio-panel>
<label>radio 1</label>
<input type="radio" value="1" checked />
</cds-radio-panel>
<cds-radio-panel>
<label>radio 2</label>
<input type="radio" value="2" />
</cds-radio-panel>
<cds-control-message>message text</cds-control-message>
</cds-radio-group>
`);

component = element.querySelector<CdsRadioGroup>('cds-radio-group');

await componentIsStable(component);
const radio1 = component.querySelectorAll('cds-radio-panel')[0];
const radio2 = component.querySelectorAll('cds-radio-panel')[1];
expect(radio1.inputControl.hasAttribute('checked')).toBe(true);
expect(radio2.inputControl.hasAttribute('checked')).toBe(false);
});

it('should allow manually setting the radio-panel input name', async () => {
element = await createTestElement(html`
<cds-radio-group>
<label>radio group</label>
<cds-radio-panel>
<label>radio 1</label>
<input type="radio" name="my-radio" value="1" checked />
</cds-radio-panel>
<cds-radio-panel>
<label>radio 2</label>
<input type="radio" name="my-radio" value="2" />
</cds-radio-panel>
<cds-control-message>message text</cds-control-message>
</cds-radio-group>
`);

component = element.querySelector<CdsRadioGroup>('cds-radio-group');

await componentIsStable(component);
const radio1 = component.querySelectorAll('cds-radio-panel')[0];
const radio2 = component.querySelectorAll('cds-radio-panel')[1];
expect(radio1.inputControl.name).toBe(radio2.inputControl.name);
expect(radio1.inputControl.name).toEqual('my-radio');
});
});
2 changes: 1 addition & 1 deletion projects/core/src/radio/radio-group.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { CdsRadio } from './radio.element.js';
* @slot - For projecting cds-radio controls
*/
export class CdsRadioGroup extends CdsInternalControlGroup {
@querySlotAll('cds-radio, cds-radio') protected controls: NodeListOf<CdsRadio>;
@querySlotAll('cds-radio, cds-radio-panel') protected controls: NodeListOf<CdsRadio>;

@id() protected radioName: string;

Expand Down

0 comments on commit 07baca7

Please sign in to comment.