Skip to content

Commit 3d2b006

Browse files
author
Kubit
committed
Improve inputs search
1 parent 4718fa1 commit 3d2b006

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

src/components/input/types/inputTheme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export type InputBasicStateProps = {
4848
label?: TypographyTypes & {
4949
type?: LABEL_TYPE;
5050
};
51+
focusVisibleCustom?: CommonStyleType;
5152
labelContainer?: CommonStyleType;
5253
placeholder?: TypographyTypes;
5354
asterisk?: TypographyTypes;

src/components/inputCurrency/__tests__/inputCurrency.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33

44
import { axe } from 'jest-axe';
55

6-
import { FormatNumber, InputContentPosition, InputState } from '@/components/input/types';
6+
import { InputContentPosition, InputState } from '@/components/input/types';
77
import { renderProvider } from '@/tests/renderProvider/renderProvider.utility';
88
import { POSITIONS } from '@/types/positions';
99

@@ -28,7 +28,7 @@ const format = {
2828
style: 'decimal',
2929
maximumFractionDigits: 3,
3030
minimumFractionDigits: 1,
31-
} as FormatNumber;
31+
};
3232

3333
describe('New Input Currency Component', () => {
3434
test('Should render InputCurrency component', async () => {

src/components/inputDate/hooks/useInputDate.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type ParamsType = ParamsTypeInputHook & {
3737
onWrapperBlur?: FocusEventHandler<HTMLDivElement>;
3838
};
3939

40-
type ReturnType = ReturnTypeInputHook & {
40+
type ReturnType = Omit<ReturnTypeInputHook, 'eventKeyPressRef'> & {
4141
// modifiers
4242
dateFormatted: Date[];
4343
calendarOpen: boolean;
@@ -393,6 +393,19 @@ export const useInputDate = ({
393393
if (props.hasRange) {
394394
handleSetValue(`${getDate(orderedDates[0])} ${getDate(orderedDates[1])}`);
395395
} else if (dateValue?.length === props.format?.length) {
396+
if (inputRef?.current) {
397+
// Inner input value should be set before the rerendering
398+
// This avoid calling onChange event when input.value is different from the current value when picking a date
399+
inputRef.current.value = dateValue;
400+
// When selecting a date from the calendar, set the cursor to the end of the input
401+
eventKeyPressRef.current = {
402+
key: '',
403+
cursor: {
404+
start: dateValue.length,
405+
end: dateValue.length,
406+
},
407+
};
408+
}
396409
handleSetValue(dateValue);
397410
}
398411

@@ -431,6 +444,7 @@ export const useInputDate = ({
431444
const {
432445
value,
433446
state,
447+
eventKeyPressRef,
434448
inputRef,
435449
handleChangeInternal,
436450
handleBlurInternal,

src/components/inputSearch/components/popoverSearchList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export const PopoverSearchListComponent = (
160160
hasBackDrop
161161
aria-modal={useActionBottomSheet ? true : undefined}
162162
blockBack={props.blockBackPopover}
163-
component={useActionBottomSheet ? PopoverComponentType.DIV : undefined}
163+
component={PopoverComponentType.DIV}
164164
dataTestId={`${props.dataTestId}Popover`}
165165
focusFirstDescendantAutomatically={false}
166166
focusLastElementFocusedAfterClose={false}

src/components/inputSearch/hooks/__tests__/useInputSearch.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const mockProps = {
6262

6363
const mockUseInputValues = {
6464
value: 'op',
65+
eventKeyPressRef: { current: undefined },
6566
inputRef: { current: document.createElement('input') },
6667
state: InputState.ACTIVE,
6768
handleBlurInternal: jest.fn(),

src/components/inputSearch/hooks/useInputSearch.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export const useInputSearch = ({
251251
}
252252
}
253253
// Focus the item
254-
(options[selectedOption] as HTMLElement).focus();
254+
(options[selectedOption] as HTMLElement | undefined)?.focus();
255255
};
256256

257257
// When arrow down
@@ -304,6 +304,11 @@ export const useInputSearch = ({
304304
setInputPopoverText(props.value ?? '');
305305
}, [props.value]);
306306

307+
// Open or close the popover from external props
308+
useEffect(() => {
309+
handleOpenOptions(props.open);
310+
}, [props.open]);
311+
307312
// Set focus on popover input when show
308313
const actionBottomSheetRefCb = useCallback(node => {
309314
node?.querySelector('input')?.focus();

0 commit comments

Comments
 (0)