Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3098,6 +3098,7 @@ export namespace Components {
* The theme determines the visual appearance of the component.
*/
"theme"?: "ios" | "md" | "ionic";
"updateRadiosTabindex": () => Promise<void>;
/**
* the value of the radio group.
*/
Expand Down
11 changes: 10 additions & 1 deletion core/src/components/radio-group/radio-group.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ComponentInterface, EventEmitter } from '@stencil/core';
import { Build, Component, Element, Event, Host, Listen, Method, Prop, State, Watch, h } from '@stencil/core';
import { checkInvalidState } from '@utils/forms';
import { renderHiddenInput } from '@utils/helpers';
import { debounce, renderHiddenInput } from '@utils/helpers';
import { hostContext } from '@utils/theme';

import { getIonTheme } from '../../global/ionic-global';
Expand Down Expand Up @@ -110,6 +110,15 @@ export class RadioGroup implements ComponentInterface {
this.valueChanged(this.value);
}

/** @internal - Recompute which radio has tabindex 0. Call when radios are added/removed. */
@Method()
async updateRadiosTabindex() {
this.scheduleTabindexUpdate();
}

/** Ensures that the tabindex update is debounced and only called once. */
private scheduleTabindexUpdate = debounce(() => this.setRadioTabindex(this.value), 0);

private setRadioTabindex = (value: any | undefined) => {
const radios = this.getRadios();

Expand Down
2 changes: 2 additions & 0 deletions core/src/components/radio/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ export class Radio implements ComponentInterface {
if (radioGroup) {
this.updateState();
addEventListener(radioGroup, 'ionValueChange', this.updateState);
radioGroup.updateRadiosTabindex();
}
}

disconnectedCallback() {
const radioGroup = this.radioGroup;
if (radioGroup) {
removeEventListener(radioGroup, 'ionValueChange', this.updateState);
radioGroup.updateRadiosTabindex();
this.radioGroup = null;
}
}
Expand Down
Loading