Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/components/shared/wizard/RenderMultiField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,26 @@ const ShowValue = ({
showCheck,
onBlur,
}: {
setEditMode: (e: boolean) => void
setEditMode: (e: boolean) => void
form: FieldProps["form"]
field: FieldProps["field"]
showCheck: boolean,
onBlur: () => void
}) => {
return (
<div
tabIndex={0}
onClick={() => setEditMode(true)}
onFocus={() => setEditMode(true)} // <-- activate edit mode on focus
onKeyDown={e => {
if (e.key === "Enter" || e.key === " ") {
setEditMode(true);
e.preventDefault();
}
}}

onBlur={onBlur}
className="show-edit"
>
<div
tabIndex={0}
onClick={() => setEditMode(true)}
onFocus={() => setEditMode(true)} // <-- activate edit mode on focus
onKeyDown={e => {
if (e.key === "Enter" || e.key === " ") {
setEditMode(true);
e.preventDefault();
}
}}
onBlur={onBlur}
className="show-edit"
>
{field.value instanceof Array && field.value.length !== 0 ? (
<ul>
{field.value.map((item, key) => (
Expand Down
28 changes: 18 additions & 10 deletions src/hooks/wizardHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,24 @@ export const useClickOutsideField = (
childRef.current.focus();
}

const handleBlur = (e: FocusEvent) => {
// Check if blur moves to an element outside childRef
if (childRef.current && !childRef.current.contains(e.relatedTarget as Node)) {
setEditMode(false);
}
};

if (childRef.current) {
childRef.current.addEventListener("blur", handleBlur, true); // capture phase
}
/* TODO: Fix handleBlur
This is supposed to handle blur for tab navigation, which it does.
But it also triggers on mouse clicks that are inside the field, causing
unintended blurs and sometimes other elements besides the input element
to not work. A proper fix should properly set edit mode to false when the
field is left via keyboard navigation, but not set edit mode to false when
the user is clicking inside of the field.
*/
// const handleBlur = (e: FocusEvent) => {
// // Check if blur moves to an element outside childRef
// if (childRef.current && !childRef.current.contains(e.relatedTarget as Node)) {
// setEditMode(false);
// }
// };

// if (childRef.current) {
// childRef.current.addEventListener("blur", handleBlur, true); // capture phase
// }

// Adding event listener for detecting click outside
window.addEventListener("mousedown", handleClickOutside);
Expand Down