Skip to content

Commit

Permalink
fix(radio): disable tabindex on disabled radio (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
skhamvon authored Jul 17, 2023
1 parent dc86eb9 commit cfb31b6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ describe('spec:ods-radio-controller', () => {
controller.setButtonTabindex(n);
expect(component.buttonTabindex).toBe(n);
});

it('should set buttonTabindex value to minus one if disabled', () => {
const n = 1 + Math.round(Math.random() * 5);
setup({ buttonTabindex: 0, disabled: true });
controller.setButtonTabindex(n);
expect(component.buttonTabindex).toBe(-1);
});
});

describe('methods:updateDisabledOnChild', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class OdsRadioController extends OdsComponentController<OdsRadio> {
}

setButtonTabindex(value: number): void {
this.component.buttonTabindex = value;
this.component.buttonTabindex = this.component.disabled ? -1 : value;
}

updateDisabledOnChild(disabled: boolean): void {
Expand Down Expand Up @@ -59,15 +59,15 @@ export class OdsRadioController extends OdsComponentController<OdsRadio> {
}

/**
*
* @param value
*
* @param value
*/
watchValue(value: string): void {
this.logger.log(`[radio=${this.component.value}]`, 'value changed', { value });
}

/**
*
*
*/
beforeInit(): void {
this.logger.log(`[radio=${this.component.value}]`, 'connectedCallback');
Expand All @@ -83,7 +83,7 @@ export class OdsRadioController extends OdsComponentController<OdsRadio> {
}

/**
*
*
*/
afterInit(): void {
this.component.radioizedComponent = (this.component.el.firstElementChild as unknown) as (HTMLElement & OdsRadioizable);
Expand All @@ -96,7 +96,7 @@ export class OdsRadioController extends OdsComponentController<OdsRadio> {
}

/**
*
*
*/
onDestroy(): void {
const radioGroup = this.component.radioGroup;
Expand All @@ -109,8 +109,8 @@ export class OdsRadioController extends OdsComponentController<OdsRadio> {
}

/**
*
* @param checking
*
* @param checking
*/
updateState(checking?: boolean): void {
if (this.component.radioGroup) {
Expand All @@ -127,8 +127,8 @@ export class OdsRadioController extends OdsComponentController<OdsRadio> {
}

/**
*
* @param event
*
* @param event
*/
async handleLabelClick(event: MouseEvent) {
this.logger.log(`[radio=${this.component.value}]`, 'click');
Expand All @@ -137,8 +137,8 @@ export class OdsRadioController extends OdsComponentController<OdsRadio> {
}

/**
*
* @param event
*
* @param event
*/
async handleLabelKeyEvent(event: KeyboardEvent) {
this.logger.log(`[radio=${this.component.value}]`, 'key event', { event });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class OsdsRadio implements OdsRadio<OdsStencilMethods<OdsRadioMethods>, O
@Watch('disabled')
updateDisabledOnChild(disabled: boolean): void {
this.controller.updateDisabledOnChild(disabled);
this.buttonTabindex = disabled ? -1 : 0;
}

@Watch('checking')
Expand Down
11 changes: 11 additions & 0 deletions packages/stencil/components/radio/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
</osds-radio>
</osds-radio-group>

<p>radio disabled</p>
<osds-radio-group id="radio-group-a" disabled>
<osds-radio value="val-tile1">
<osds-tile>myTile1</osds-tile>
</osds-radio>
<osds-radio value="val-tile2">
<osds-tile >myTile2</osds-tile>
</osds-radio>
</osds-radio-group>



<script type="module">
document.addEventListener('odsInitialized', ({detail}) => {
Expand Down

0 comments on commit cfb31b6

Please sign in to comment.