Skip to content

Commit af7c7ae

Browse files
committed
fix/multiselect fields by Tab navigation
1 parent fc2a141 commit af7c7ae

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/components/events/partials/ModalTabsAndPages/NewMetadataPage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const NewMetadataPage = ({
1818
header?: ParseKeys
1919
}) => {
2020
const { t } = useTranslation();
21-
console.log(metadataCatalogs);
2221
return (
2322
<ModalContentTable>
2423
{

src/components/shared/DropDown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ const DropDown = <T, >({
209209
<AsyncSelect
210210
ref={selectRef}
211211
{...commonProps}
212-
openMenuOnFocus={false}
212+
openMenuOnFocus={false}
213213
noOptionsMessage={() => t("SELECT_NO_MATCHING_RESULTS")}
214214
cacheOptions
215215
defaultOptions={formatOptions(

src/components/shared/wizard/RenderMultiField.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ const RenderMultiField = ({
8383

8484
// reset inputValue
8585
setInputValue("");
86-
} else {
87-
setEditMode(false);
88-
}
86+
}
8987
};
9088

9189
// Remove item/value from inserted field values
@@ -118,6 +116,10 @@ const RenderMultiField = ({
118116
field={field}
119117
form={form}
120118
showCheck={showCheck}
119+
onBlur = {() => {
120+
submitValue();
121+
setEditMode(false);
122+
}}
121123
/>
122124
)
123125
);
@@ -199,16 +201,26 @@ const ShowValue = ({
199201
form: { initialValues },
200202
field,
201203
showCheck,
204+
onBlur,
202205
}: {
203-
setEditMode: (e: boolean) => void
206+
setEditMode: (e: boolean) => void
204207
form: FieldProps["form"]
205208
field: FieldProps["field"]
206209
showCheck: boolean,
210+
onBlur: () => void
207211
}) => {
208212
return (
209213
<div
210214
tabIndex={0}
211215
onClick={() => setEditMode(true)}
216+
onFocus={() => setEditMode(true)} // <-- activate edit mode on focus
217+
onKeyDown={e => {
218+
if (e.key === "Enter" || e.key === " ") {
219+
setEditMode(true);
220+
e.preventDefault();
221+
}
222+
}}
223+
onBlur={onBlur}
212224
className="show-edit"
213225
>
214226
{field.value instanceof Array && field.value.length !== 0 ? (

src/hooks/wizardHooks.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ export const useClickOutsideField = (
118118
childRef.current.focus();
119119
}
120120

121+
const handleBlur = (e: FocusEvent) => {
122+
// Check if blur moves to an element outside childRef
123+
if (childRef.current && !childRef.current.contains(e.relatedTarget as Node)) {
124+
setEditMode(false);
125+
}
126+
};
127+
128+
if (childRef.current) {
129+
childRef.current.addEventListener("blur", handleBlur, true); // capture phase
130+
}
131+
121132
// Adding event listener for detecting click outside
122133
window.addEventListener("mousedown", handleClickOutside);
123134

0 commit comments

Comments
 (0)