Repository: ionic-team/ionic-framework
File: core/src/components/action-sheet/action-sheet.tsx (TypeScript)

Code before:
    // Focus the next radio button
    if (nextEl) {
      const allButtons = this.getButtons();
      const radioButtons = this.getRadioButtons();

      const buttonIndex = radioButtons.findIndex((b) => {
        const buttonId = this.getButtonId(b, allButtons.indexOf(b));
        return buttonId === nextEl?.id;
      });

      if (buttonIndex !== -1) {
        this.selectRadioButton(radioButtons[buttonIndex]);
        nextEl.focus();
      }
    }
  }

  connectedCallback() {
    prepareOverlay(this.el);
    this.triggerChanged();
  }

  disconnectedCallback() {
    if (this.gesture) {
      this.gesture.destroy();
      this.gesture = undefined;
    }
    this.triggerController.removeClickListener();
  }

  componentWillLoad() {
    if (!this.htmlAttributes?.id) {
      setOverlayId(this.el);
    }
    // Initialize activeRadioId for radio buttons
    this.buttonsChanged();
  }

  componentDidLoad() {
    /**
     * Only create gesture if:
     * 1. A gesture does not already exist
     * 2. App is running in iOS mode
     * 3. A wrapper ref exists
     * 4. A group ref exists
     */
    const { groupEl, wrapperEl } = this;
    if (!this.gesture && getIonMode(this) === 'ios' && wrapperEl && groupEl) {
      readTask(() => {
        const isScrollable = groupEl.scrollHeight > groupEl.clientHeight;
        if (!isScrollable) {

Review comment (refactor):
```suggestion
  onKeydown(ev: KeyboardEvent) {
    // Only handle keyboard navigation if we have radio buttons
    if (!this.hasRadioButtons || !this.presented) {
      return;
    }

    const target = ev.target as HTMLElement;

    // Ignore if the target element is not within the action sheet or not a radio button
    if (
      !this.el.contains(target) ||
      !target.classList.contains('action-sheet-button') ||
      target.getAttribute('role') !== 'radio'
    ) {
      return;
    }

    // Get all radio button elements and filter out disabled ones
    const radios = Array.from(this.el.querySelectorAll('.action-sheet-button[role="radio"]')).filter(
      (el) => !(el as HTMLButtonElement).disabled
    ) as HTMLButtonElement[];

    const currentIndex = radios.findIndex((radio) => radio.id === target.id);
    if (currentIndex === -1) {
      return;
    }

    const allButtons = this.getButtons();
    const radioButtons = this.getRadioButtons();

    // Build a map of button element IDs to their ActionSheetButton config objects.
    // This allows us to quickly look up which button config corresponds to a DOM element
    // when handling keyboard navigation (e.g., when user presses Space/Enter or arrow keys).
    // The key is the ID that was set on the DOM element during render, and the value is
    // the ActionSheetButton config that contains the handler and other properties.
    const buttonIdMap = new Map<string, ActionSheetButton>();
    radioButtons.forEach((b) => {
      const allIndex = allButtons.indexOf(b);
      const buttonId = this.getButtonId(b, allIndex);
      buttonIdMap.set(buttonId, b);
    });

    let nextEl: HTMLButtonElement | undefined;

    if (['ArrowDown', 'ArrowRight'].includes(ev.key)) {
      ev.preventDefault();
      ev.stopPropagation();

      nextEl = currentIndex === radios.length - 1 ? radios[0] : radios[currentIndex + 1];
    } else if (['ArrowUp', 'ArrowLeft'].includes(ev.key)) {
      ev.preventDefault();
      ev.stopPropagation();

      nextEl = currentIndex === 0 ? radios[radios.length - 1] : radios[currentIndex - 1];
    } else if (ev.key === ' ' || ev.key === 'Enter') {
      ev.preventDefault();
      ev.stopPropagation();

      const button = buttonIdMap.get(target.id);
      if (button) {
        this.selectRadioButton(button);
        this.buttonClick(button);
      }
      return;
    }

    // Focus the next radio button
    if (nextEl) {
      const button = buttonIdMap.get(nextEl.id);
      if (button) {
        this.selectRadioButton(button);
        nextEl.focus();
      }
    }
  }
```

Simplify to avoid querying the buttons multiple times. You may want to make this change yourself instead of accepting mine as I probably messed up spacing when I pasted. 

Code after:
      ev.preventDefault();
      ev.stopPropagation();

      nextEl = currentIndex === 0 ? radios[radios.length - 1] : radios[currentIndex - 1];
    } else if (ev.key === ' ' || ev.key === 'Enter') {
      ev.preventDefault();
      ev.stopPropagation();

      const button = buttonIdMap.get(target.id);
      if (button) {
        this.selectRadioButton(button);
        this.buttonClick(button);
      }

      return;
    }

    // Focus the next radio button
    if (nextEl) {
      const button = buttonIdMap.get(nextEl.id);
      if (button) {
        this.selectRadioButton(button);
        nextEl.focus();
      }
    }
  }

  connectedCallback() {
    prepareOverlay(this.el);
    this.triggerChanged();
  }

  disconnectedCallback() {
    if (this.gesture) {
      this.gesture.destroy();
      this.gesture = undefined;
    }
    this.triggerController.removeClickListener();
  }

  componentWillLoad() {
    if (!this.htmlAttributes?.id) {
      setOverlayId(this.el);
    }
    // Initialize activeRadioId for radio buttons
    this.buttonsChanged();
  }

  componentDidLoad() {
    /**
     * Only create gesture if: