<div class="container"></div>
const useState = React.useState

const App = () => {
  const [visible, setVisible] = useState(false);
  return (
    <>
      <button onClick={() => setVisible(true)}>表示</button>
      {visible && (
        <div
          style={{ border: 'solid' }}
          tabIndex={0}
          ref={(e) => e?.focus()}
          onBlur={() => setVisible(false)}
        >
          表示内容
        </div>
      )}
    </>
  );
};

ReactDOM.render(<App />, document.querySelector(".container"));
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js
  3. https://cdn.skypack.dev/@types/react@17.0.4