Refactor inline editing into shared hook
All checks were successful
Deploy Sokko G / deploy (push) Successful in 7s

This commit is contained in:
Shinuwa 2026-08-02 11:27:26 +02:00
parent 1879b245fb
commit 1e4ac4259b
9 changed files with 239 additions and 205 deletions

View file

@ -1,6 +1,7 @@
// Rôle : fournit l'outil Combos avec palettes d'inputs et rendu visuel par périphérique.
import { useEffect, useMemo, useState } from "react";
import { Icon } from "../../../components/Icon.jsx";
import { useInlineEdit } from "../../../hooks/useInlineEdit.js";
import {
applyGroupedReorderOperation,
getGroupedEntries,
@ -240,32 +241,19 @@ function ComboSequence({ inputs, device, emptyLabel, activeStepIndex = -1, onSel
}
function InlineTextInput({ value, onCommit, className, ariaLabel, placeholder = "" }) {
const [draft, setDraft] = useState(value);
useEffect(() => {
setDraft(value);
}, [value]);
function commit() {
const cleanDraft = draft.trim();
if (cleanDraft !== value) onCommit(cleanDraft);
}
const inlineEdit = useInlineEdit({
value,
onCommit,
blurOnEscape: true
});
return (
<input
className={className}
value={draft}
placeholder={placeholder}
onChange={(event) => setDraft(event.target.value)}
onBlur={commit}
onKeyDown={(event) => {
if (event.key === "Enter") event.currentTarget.blur();
if (event.key === "Escape") {
setDraft(value);
event.currentTarget.blur();
}
}}
aria-label={ariaLabel}
{...inlineEdit.getInputProps({
className,
placeholder,
"aria-label": ariaLabel
})}
/>
);
}