Browse Source

refactor: remove read-only state management from question inputs and update snap list ignore selectors to improve touch interaction reliability

master
mortezaei 6 days ago
parent
commit
36cfcc8a76
  1. 10
      src/components/Componentes/question-snap-list.tsx
  2. 22
      src/components/Componentes/question-text.tsx

10
src/components/Componentes/question-snap-list.tsx

@ -26,6 +26,13 @@ const DRAG_IGNORE_SELECTOR = [
"input", "input",
"textarea", "textarea",
"select", "select",
"button",
"label",
"a",
'[role="button"]',
'[role="option"]',
'[role="checkbox"]',
'[role="radio"]',
'[contenteditable="true"]', '[contenteditable="true"]',
"[data-snap-drag-ignore]", "[data-snap-drag-ignore]",
].join(", "); ].join(", ");
@ -389,7 +396,6 @@ export function QuestionSnapList({
const drag = dragRef.current; const drag = dragRef.current;
if (!drag.pointerDown) { if (!drag.pointerDown) {
event.preventDefault();
return; return;
} }
@ -401,7 +407,7 @@ export function QuestionSnapList({
if (!drag.engaged) { if (!drag.engaged) {
if (Math.abs(drag.startY - y) < DRAG_ENGAGE_DISTANCE) { if (Math.abs(drag.startY - y) < DRAG_ENGAGE_DISTANCE) {
event.preventDefault();
// Allow micro-movements during a tap to produce native click/focus events
return; return;
} }
drag.engaged = true; drag.engaged = true;

22
src/components/Componentes/question-text.tsx

@ -33,7 +33,6 @@ export default function QuestionText({
const [localValue, setLocalValue] = useState( const [localValue, setLocalValue] = useState(
isMuted ? "" : String(value ?? ""), isMuted ? "" : String(value ?? ""),
); );
const [isReadOnly, setIsReadOnly] = useState(true);
const debounceTimerRef = useRef<NodeJS.Timeout | null>(null); const debounceTimerRef = useRef<NodeJS.Timeout | null>(null);
useEffect(() => { useEffect(() => {
@ -60,17 +59,12 @@ export default function QuestionText({
}; };
const handleBlur = () => { const handleBlur = () => {
setIsReadOnly(true);
if (debounceTimerRef.current) { if (debounceTimerRef.current) {
clearTimeout(debounceTimerRef.current); clearTimeout(debounceTimerRef.current);
} }
setAnswerValue(question, localValue); setAnswerValue(question, localValue);
}; };
const handleFocus = () => {
setIsReadOnly(false);
};
const stringValue = localValue.trim(); const stringValue = localValue.trim();
const isEmailQuestion = question.type === "email" || question.validation?.format === "email"; const isEmailQuestion = question.type === "email" || question.validation?.format === "email";
@ -107,11 +101,9 @@ export default function QuestionText({
> >
<input <input
type="text" type="text"
name="off_email"
readOnly={isReadOnly || disabled || isMuted}
onFocus={handleFocus}
onTouchStart={handleFocus}
autoComplete="one-time-code"
inputMode="text"
name="text_field"
autoComplete="off"
autoCorrect="off" autoCorrect="off"
autoCapitalize="none" autoCapitalize="none"
spellCheck="false" spellCheck="false"
@ -154,12 +146,10 @@ export default function QuestionText({
<QuestionTitle question={question} /> <QuestionTitle question={question} />
<input <input
type={isNumericQuestion ? "tel" : "text"} type={isNumericQuestion ? "tel" : "text"}
inputMode={isNumericQuestion ? "numeric" : undefined}
inputMode={isNumericQuestion ? "numeric" : "text"}
pattern={isNumericQuestion ? "[0-9]*" : undefined} pattern={isNumericQuestion ? "[0-9]*" : undefined}
readOnly={isReadOnly || disabled || isMuted}
onFocus={handleFocus}
onTouchStart={handleFocus}
autoComplete="one-time-code"
name="text_field"
autoComplete="off"
autoCorrect="off" autoCorrect="off"
autoCapitalize="none" autoCapitalize="none"
spellCheck="false" spellCheck="false"

Loading…
Cancel
Save