Repository: hashicorp/vault
File: ui/lib/open-api-explorer/addon/components/swagger-ui.js (JavaScript)

Code before:
    if (container) {
      const observer = new MutationObserver(() => {
        this.updateCaretTabIndex();
        this.updateCopyToClipboard();
        this.updateTryItOutButtonDescription();
      });
      observer.observe(container, { childList: true, subtree: true });
      // Run once on initial load
      this.updateCaretTabIndex();
      this.updateCopyToClipboard();
      this.updateTryItOutButtonDescription();
    }
  }

  updateCaretTabIndex() {
    document.querySelectorAll('.opblock-control-arrow').forEach((el) => {
      el.tabIndex = 0;
    });
  }

  updateCopyToClipboard() {
    document.querySelectorAll('.copy-to-clipboard').forEach((div) => {
      div.tabIndex = 0;
      div.setAttribute('role', 'button');
      div.addEventListener('keydown', function (e) {
        if (e.key === 'Enter' || e.key === ' ') {
          const svg = div.querySelector('svg');
          if (svg) {
            svg.dispatchEvent(new MouseEvent('click', { bubbles: true }));
          }
          e.preventDefault();
        }
      });
    });
  }

  updateTryItOutButtonDescription() {
    document.querySelectorAll('.try-out button').forEach((el) => {
      const warning =
        'Caution: This will make requests to the Vault server on your behalf which may create or delete items.';

      el.setAttribute('aria-description', warning);
    });
  }
}


Review comment (suggestion):
Could the [keys.js](https://github.com/hashicorp/vault/blob/main/ui/lib/core/addon/utils/keys.js#L6-L18) util be used to replace the strings here? (Looks like space will have to be added)

Code after:
    const container = document.querySelector('.swagger-ui');
    if (container) {
      this.observer = new MutationObserver(() => {
        this.updateCaretTabIndex();
        this.updateCopyToClipboard();
        this.updateTryItOutButtonDescription();
      });
      this.observer.observe(container, { childList: true, subtree: true });
      // Run once on initial load
      this.updateCaretTabIndex();
      this.updateCopyToClipboard();
      this.updateTryItOutButtonDescription();
    }
  }

  updateCaretTabIndex() {
    document.querySelectorAll('.opblock-control-arrow').forEach((el) => {
      el.tabIndex = 0;
    });
  }

  updateCopyToClipboard() {
    document.querySelectorAll('.copy-to-clipboard').forEach((div) => {
      div.tabIndex = 0;
      div.setAttribute('role', 'button');
      div.addEventListener('keydown', function (e) {
        if (e.key === keys.ENTER || e.key === keys.SPACE) {
          const svg = div.querySelector('svg');
          if (svg) {
            svg.dispatchEvent(new MouseEvent('click', { bubbles: true }));
          }
          e.preventDefault();
        }
      });
    });
  }

  updateTryItOutButtonDescription() {
    document.querySelectorAll('.try-out button').forEach((el) => {
      const warning =
        'Caution: This will make requests to the Vault server on your behalf which may create or delete items.';

      el.setAttribute('aria-description', warning);
    });
  }

  willDestroy() {
    this.observer.disconnect();
    super.willDestroy();
  }
}