Skip to content

Commit f373ca8

Browse files
committed
Add option to hide dropdown for special cases
1 parent fe2bc4f commit f373ca8

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/components/SearchSelectInput/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export type Props<
4545
) => OPTION[];
4646
onSearchValueChange?: (value: string | undefined) => void;
4747
onShowDropdownChange?: (value: boolean) => void;
48+
onEnterWithoutOption?: (value: string | undefined) => void;
4849

4950
selectedOnTop: boolean;
5051
}, OMISSION>
@@ -74,6 +75,7 @@ export type Props<
7475
| 'hasValue'
7576
| 'hideOptionFilter'
7677
| 'onSelectAllButtonClick'
78+
| 'onEnterWithoutOption'
7779
| OMISSION
7880
>
7981
& ({
@@ -211,10 +213,14 @@ function SearchSelectInput<
211213
if (onShowDropdownChange) {
212214
onShowDropdownChange(false);
213215
}
216+
setSearchInputValue(undefined);
217+
if (onSearchValueChange) {
218+
onSearchValueChange(undefined);
219+
}
214220
if (onEnterWithoutOption) {
215-
onEnterWithoutOption();
221+
onEnterWithoutOption(searchInputValue);
216222
}
217-
}, [onShowDropdownChange, onEnterWithoutOption]);
223+
}, [searchInputValue, onShowDropdownChange, onEnterWithoutOption, onSearchValueChange]);
218224

219225
const handleChangeDropdown = useCallback(
220226
(myVal: boolean) => {

src/components/SelectInputContainer/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export type SelectInputContainerProps<
6363
onClearButtonClick: () => void;
6464
onSelectAllButtonClick?: () => void;
6565
onEnterWithoutOption?: () => void;
66+
dropdownHidden?: boolean;
6667
}, OMISSION>
6768
& Omit<InputContainerProps, 'input'>
6869
);
@@ -126,6 +127,7 @@ function SelectInputContainer<
126127
required,
127128
variant,
128129
errorOnTooltip,
130+
dropdownHidden,
129131
} = props;
130132

131133
const options = optionsFromProps ?? (emptyList as OPTION[]);
@@ -183,11 +185,9 @@ function SelectInputContainer<
183185
if (readOnly) {
184186
return;
185187
}
186-
if (options.length > 0) {
187-
handleShowDropdown();
188-
}
188+
handleShowDropdown();
189189
},
190-
[readOnly, handleShowDropdown, options],
190+
[readOnly, handleShowDropdown],
191191
);
192192

193193
const handlePopupBlur = useCallback(
@@ -259,6 +259,8 @@ function SelectInputContainer<
259259
? `${strings.infoMessageAnd} ${totalOptionsCount - optionsCount} ${strings.infoMessageMore}`
260260
: undefined;
261261

262+
const dropdownShownActual = dropdownShown && !dropdownHidden;
263+
262264
return (
263265
<>
264266
<InputContainer
@@ -311,11 +313,11 @@ function SelectInputContainer<
311313
onClick={handleToggleDropdown}
312314
variant="tertiary"
313315
name={undefined}
314-
title={dropdownShown
316+
title={dropdownShownActual
315317
? strings.buttonTitleClose
316318
: strings.buttonTitleOpen}
317319
>
318-
{dropdownShown
320+
{dropdownShownActual
319321
? <ArrowUpSmallFillIcon className={styles.icon} />
320322
: <ArrowDownSmallFillIcon className={styles.icon} />}
321323
</Button>
@@ -340,7 +342,7 @@ function SelectInputContainer<
340342
/>
341343
)}
342344
/>
343-
{dropdownShown && (
345+
{dropdownShownActual && (
344346
<Popup
345347
elementRef={popupRef}
346348
parentRef={inputSectionRef}

src/components/domain/KeywordSearchSelectInput/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,23 @@ function KeywordSearchSelectInput() {
278278
);
279279
}, [navigate]);
280280

281-
const handleSearchInputEnter = useCallback(() => {
281+
const handleSearchInputEnter = useCallback((text: string | undefined) => {
282282
// NOTE: We are not deliberately not using debouncedSearchText here
283-
const searchStringSafe = searchText?.trim() ?? '';
283+
const searchStringSafe = text?.trim() ?? '';
284284
if (searchStringSafe.length > 0) {
285285
navigate(
286286
'search',
287-
{ search: `${KEY_URL_SEARCH}=${searchText}` },
287+
{ search: `${KEY_URL_SEARCH}=${text}` },
288288
);
289289
}
290290
}, [
291-
searchText,
292291
navigate,
293292
]);
294293

295294
return (
296295
<SearchSelectInput
297296
// eslint-disable-next-line react/jsx-props-no-spreading
297+
dropdownHidden={isNotDefined(searchText) || searchText.trim().length <= 0}
298298
name="keyword"
299299
options={undefined}
300300
value={undefined}

src/views/DrefFinalReportForm/Overview/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ function Overview(props: Props) {
404404
<>
405405
{strings.finalReportPeopleTargeted}
406406
<Link
407-
title={strings.odrefFormClickEmergencyResponseFramework}
407+
title={strings.drefFormClickEmergencyResponseFramework}
408408
href={peopleTargetedLink}
409409
external
410410
>

0 commit comments

Comments
 (0)