Standardize modal focus and keyboard behavior
This commit is contained in:
parent
e87edda5c7
commit
954240adf9
15 changed files with 331 additions and 139 deletions
|
|
@ -1,30 +1,10 @@
|
|||
// Rôle : affiche la modale d'import/export texte partagée par les outils compatibles.
|
||||
import { useEffect } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { Icon } from "../../../components/Icon.jsx";
|
||||
import { lockBodyScroll } from "../../../utils/bodyScrollLock.js";
|
||||
import { Modal } from "../../../components/Modal.jsx";
|
||||
|
||||
export function TextImportModal({ title, value, placeholder, submitLabel, readOnly = false, error = "", info = "", onChange, onSubmit, onCopy, onClose }) {
|
||||
useEffect(() => {
|
||||
function handleKeyDown(event) {
|
||||
if (event.key === "Escape") {
|
||||
event.stopPropagation();
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
|
||||
const unlock = lockBodyScroll();
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
return () => {
|
||||
unlock();
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, [onClose]);
|
||||
|
||||
return createPortal(
|
||||
<div className="confirm-modal-root text-import-modal-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={onClose} />
|
||||
<section className="confirm-modal nds-modal text-import-modal-dialog" role="dialog" aria-modal="true" aria-labelledby="text-import-title">
|
||||
return (
|
||||
<Modal rootClassName="confirm-modal-root text-import-modal-root" dialogClassName="confirm-modal nds-modal text-import-modal-dialog" labelledBy="text-import-title" onRequestClose={onClose}>
|
||||
<header>
|
||||
<h2 id="text-import-title">{title}</h2>
|
||||
<button className="drawer-close-button nds-icon-button" data-size="sm" type="button" onClick={onClose} aria-label="Fermer" title="Fermer">
|
||||
|
|
@ -33,7 +13,7 @@ export function TextImportModal({ title, value, placeholder, submitLabel, readOn
|
|||
</header>
|
||||
<form className="text-import-modal-form" onSubmit={onSubmit}>
|
||||
<textarea
|
||||
autoFocus
|
||||
data-modal-initial-focus=""
|
||||
className={`nds-textarea ${error ? "has-error" : ""}`.trim()}
|
||||
data-size="sm"
|
||||
readOnly={readOnly}
|
||||
|
|
@ -65,8 +45,6 @@ export function TextImportModal({ title, value, placeholder, submitLabel, readOn
|
|||
)}
|
||||
</footer>
|
||||
</form>
|
||||
</section>
|
||||
</div>,
|
||||
document.body
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue