reactjs/react-modal

Pressing enter key to close button closes the modal but the event is attached to opener element and reopens the modal

オープン

#954 opened on 2022/06/18

 (12 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (828 件のフォーク)batch import
discussioneventshelp wantedmaybe bugneeds info

Repository metrics

Stars
 (7,294 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Summary:

Steps to reproduce:

  1. Visit my demo on Codesandbox https://codesandbox.io/s/react-modal-vivyxc?file=/src/index.js
  2. Click 'Open Modal' button and press Tab. This will focus the close button
  3. Press Enter this closes the modal but reopens it. I know this is because of the onKeyUp event listener to anchor tag but this function is needed for other purposes.

Expected behavior:

Closes modal and focus move to the opener element( in this case, anchor tag)

Link to example of issue:

Codesandbox https://codesandbox.io/s/react-modal-vivyxc?file=/src/index.js

Additional notes:

Is there a way to solve this issue without removing the onKeyUp event handler?

Thanks.

コントリビューターガイド