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,10 +1,9 @@
|
|||
// Rôle : rend les contrôles modal et quick-add d'ajout d'outils toolbox.
|
||||
import { useEffect, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { useState } from "react";
|
||||
import { CompactDropdown } from "../../../components/CompactDropdown.jsx";
|
||||
import { Icon } from "../../../components/Icon.jsx";
|
||||
import { Modal } from "../../../components/Modal.jsx";
|
||||
import { Tooltip } from "../../../components/Tooltip.jsx";
|
||||
import { lockBodyScroll } from "../../../utils/bodyScrollLock.js";
|
||||
import { LIBRARY_CATEGORY_DEFINITIONS, TOOLBOX_MODULES } from "../toolboxModuleRegistry.js";
|
||||
|
||||
export function AddToolControls({ categories, descriptions, onAdd }) {
|
||||
|
|
@ -15,11 +14,6 @@ export function AddToolControls({ categories, descriptions, onAdd }) {
|
|||
title: categories[category.key]
|
||||
}));
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return undefined;
|
||||
return lockBodyScroll();
|
||||
}, [open]);
|
||||
|
||||
function addTool(type) {
|
||||
onAdd(type);
|
||||
setOpen(false);
|
||||
|
|
@ -28,7 +22,7 @@ export function AddToolControls({ categories, descriptions, onAdd }) {
|
|||
function renderToolCard(type) {
|
||||
const module = TOOLBOX_MODULES[type];
|
||||
return (
|
||||
<button key={type} className="tool-add-card" type="button" onClick={() => addTool(type)}>
|
||||
<button key={type} className="tool-add-card" type="button" data-modal-initial-focus={type === moduleCategories[0]?.types[0] ? "" : undefined} onClick={() => addTool(type)}>
|
||||
<span className="module-icon" aria-hidden="true">
|
||||
<span className={`module-icon-svg module-icon-${module.icon}`} />
|
||||
</span>
|
||||
|
|
@ -103,10 +97,8 @@ export function AddToolControls({ categories, descriptions, onAdd }) {
|
|||
)}
|
||||
</CompactDropdown>
|
||||
</div>
|
||||
{open && createPortal(
|
||||
<div className="tool-add-modal-root">
|
||||
<div className="confirm-backdrop nds-modal-backdrop" onClick={() => setOpen(false)} />
|
||||
<section className="confirm-modal nds-modal tool-add-modal" role="dialog" aria-modal="true" aria-labelledby="tool-add-modal-title">
|
||||
{open && (
|
||||
<Modal rootClassName="tool-add-modal-root" dialogClassName="confirm-modal nds-modal tool-add-modal" labelledBy="tool-add-modal-title" onRequestClose={() => setOpen(false)}>
|
||||
<header>
|
||||
<h2 id="tool-add-modal-title">Ajouter un outil</h2>
|
||||
<button className="drawer-close-button nds-icon-button" data-size="sm" type="button" onClick={() => setOpen(false)} aria-label="Fermer" title="Fermer">
|
||||
|
|
@ -121,9 +113,7 @@ export function AddToolControls({ categories, descriptions, onAdd }) {
|
|||
</section>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</div>,
|
||||
document.body
|
||||
</Modal>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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