Skip to content

Commit ba82657

Browse files
author
Kubit
committed
Improve all Input components
1 parent 8adff56 commit ba82657

22 files changed

+165
-84
lines changed

src/components/input/components/inputIcon.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22

33
import { ElementOrIcon } from '../../elementOrIcon/elementOrIcon';
44
// styles
5-
import { InputIconStyled } from '../input.styled';
5+
import { InputIconContainerStyled, InputIconStyled } from '../input.styled';
66
import { IInputIcon } from '../types/input';
77

88
const InputIconStandAloneComponent = (
@@ -22,10 +22,12 @@ const InputIconStandAloneComponent = (
2222
};
2323

2424
return (
25-
<InputIconStyled
25+
<InputIconContainerStyled
2626
ref={ref}
2727
$pointerEvents={hasAction}
28-
iconPosition={props.iconPosition}
28+
inputIconContainerStyles={
29+
props.rightIcon ? props.styles?.inputIconContainerRight : props.styles?.inputIconContainer
30+
}
2931
styles={props.styles}
3032
>
3133
<ElementOrIcon
@@ -35,7 +37,7 @@ const InputIconStandAloneComponent = (
3537
{...props.leftIcon}
3638
onClick={hasAction ? onClick : undefined}
3739
/>
38-
</InputIconStyled>
40+
</InputIconContainerStyled>
3941
);
4042
};
4143

src/components/input/input.styled.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import styled, { css } from 'styled-components';
22

3+
import { CommonStyleType } from '@/types/styles/commonStyle';
34
import { getStyles } from '@/utils/getStyles/getStyles';
45

56
// mixins
@@ -95,6 +96,16 @@ export const LoaderWrapperStyled = styled.div<LoaderStyledProps>`
9596
${({ styles }) => getStyles(styles?.loaderContainer)};
9697
`;
9798

99+
export const InputIconContainerStyled = styled.div<
100+
InputIconStyledProps & { inputIconContainerStyles?: CommonStyleType }
101+
>`
102+
display: flex;
103+
align-items: center;
104+
justify-content: center;
105+
pointer-events: ${({ $pointerEvents }) => ($pointerEvents ? 'auto' : 'none')};
106+
${({ inputIconContainerStyles }) => getStyles(inputIconContainerStyles)};
107+
`;
108+
98109
export const InputIconStyled = styled.div<InputIconStyledProps>`
99110
display: flex;
100111
align-items: center;

src/components/input/stories/argtypes.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,17 @@ export const argtypes = (variants: IThemeObjectVariants, themeSelected: string):
709709
category: CATEGORY_CONTROL.ACCESIBILITY,
710710
},
711711
},
712+
['aria-required']: {
713+
description: 'Aria required prop',
714+
type: { name: 'boolean' },
715+
control: { type: 'boolean' },
716+
table: {
717+
type: {
718+
summary: 'boolean',
719+
},
720+
category: CATEGORY_CONTROL.ACCESIBILITY,
721+
},
722+
},
712723
overrideStyles: {
713724
description: 'Styles that need to be overridden on the basic input',
714725
control: false,

src/components/input/stories/input.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const commonArgs: IInputUnControlled = {
5050
rightIcon: { icon: ICONS.ICON_CHECKMARK_THICK, altText: 'icon alt text' },
5151
secondaryLabel: labelSecondary(themeSelected),
5252
additionalInfo: additionalInfoAction(themeSelected),
53+
['aria-required']: false,
5354
loader: {
5455
variant: Object.values(variantsObject[themeSelected].LoaderVariantType || {})[0] as string,
5556
altText: 'loaderAltText',

src/components/input/types/input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ type InputAriaAttributes = Pick<
303303
| 'aria-expanded'
304304
| 'aria-invalid'
305305
| 'aria-disabled'
306+
| 'aria-required'
306307
>;
307308

308309
// Input types

src/components/inputDropdown/__tests__/inputDropdown.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,31 @@ describe('New Input Dropdown Component', () => {
192192
expect(input.getAttribute('value')).toBe('option1');
193193
});
194194

195+
it('Should allow select an option with customLabel', async () => {
196+
renderProvider(
197+
<InputDropdown
198+
{...mockProps}
199+
optionList={{
200+
options: [
201+
{
202+
label: 'option1',
203+
value: 'option1',
204+
customLabel: 'option1Custom',
205+
},
206+
],
207+
}}
208+
/>
209+
);
210+
211+
const inputOption = screen.getByText('option1');
212+
await act(async () => {
213+
fireEvent.click(inputOption);
214+
});
215+
216+
const input = screen.getByRole(ROLES.COMBOBOX);
217+
expect(input.getAttribute('value')).toBe('option1Custom');
218+
});
219+
195220
it('Should focus first option with arrow down', async () => {
196221
renderProvider(
197222
<InputDropdown

src/components/inputDropdown/components/optionsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const OptionsListComponent = (
3636
<ListOptions
3737
ref={sendRef}
3838
charsHighlighted={props.searchText?.toString()}
39-
id={props['aria-controls']}
39+
id={props.optionListId}
4040
optionVariant={props.stylesListOption.optionVariant}
4141
options={props.optionList.options}
4242
optionsContainerArias={{

src/components/inputDropdown/components/popoverSearchList.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const PopoverSearchListComponent = (
2929
const labelInResultTextWrittenByUser = useActionBottomSheet
3030
? props.inputPopoverValue
3131
: props.searchText;
32-
const { refInput, refActionBottomSheet } = ref as unknown as MultipleRef;
32+
const { refActionBottomSheet } = ref as unknown as MultipleRef;
3333

3434
const renderIconOrMessage = () => {
3535
if (!props.loading && props.noResultsText?.content) {
@@ -53,6 +53,7 @@ export const PopoverSearchListComponent = (
5353

5454
const renderSearchList = () => (
5555
<ListContainerStyled
56+
data-input-dropdown-list
5657
$height={props.optionList.options.length ? props.listOptionsHeight : ''}
5758
styles={props.styles?.[props.state]}
5859
useActionBottomSheet={useActionBottomSheet}
@@ -67,11 +68,11 @@ export const PopoverSearchListComponent = (
6768
) : (
6869
<OptionsList
6970
ref={ref}
70-
aria-controls={props['aria-controls']}
7171
loader={props.loader}
7272
loading={props.loading}
7373
loadingText={props.loadingText}
7474
optionList={props.optionList}
75+
optionListId={props.optionListId}
7576
searchText={labelInResultTextWrittenByUser}
7677
stylesListOption={props.styles.listOptions}
7778
stylesState={props.styles?.[props.state]}
@@ -84,7 +85,8 @@ export const PopoverSearchListComponent = (
8485
</ListContainerStyled>
8586
);
8687

87-
const showHeaderInput = props.hasInputInSearchList && props.styles?.[props.state]?.allowSearch;
88+
const showHeaderInput =
89+
props.hasInputInSearchList && (props.allowSearch ?? props.styles?.[props.state]?.allowSearch);
8890

8991
return (
9092
<PopoverControlled
@@ -98,7 +100,6 @@ export const PopoverSearchListComponent = (
98100
variant={props.styles?.[props.state]?.popoverVariant?.[props.device]}
99101
onCloseInternally={() => {
100102
props.onOpenOptions(false);
101-
refInput?.current?.focus();
102103
}}
103104
>
104105
{useActionBottomSheet ? (
@@ -112,6 +113,7 @@ export const PopoverSearchListComponent = (
112113
props.closeIcon?.onClick?.(e);
113114
},
114115
}}
116+
dragIcon={props.dragIcon}
115117
headerContent={
116118
showHeaderInput && (
117119
<Input
@@ -134,7 +136,6 @@ export const PopoverSearchListComponent = (
134136
// The variant is the same for all the states
135137
variant={props.styles?.[props.state]?.inputVariant as string}
136138
onChange={props.onInputPopoverChange}
137-
onKeyDown={props.onInputPopoverKeyDown}
138139
/>
139140
)
140141
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { ListOptionsOptionType } from '../../listOptions/types/listOptions';
1+
import { OptionsInputDropdown } from '../types/inputDropdown';
22

33
export const filterOptions = (
44
value: string | number | undefined,
5-
options: ListOptionsOptionType[]
6-
): ListOptionsOptionType[] => {
5+
options: OptionsInputDropdown[]
6+
): OptionsInputDropdown[] => {
77
if (!value) {
88
return options;
99
}
@@ -15,14 +15,14 @@ export const filterOptions = (
1515

1616
export const findOptionByLabel = (
1717
label: string | number | undefined,
18-
options: ListOptionsOptionType[]
19-
): ListOptionsOptionType | undefined => {
18+
options: OptionsInputDropdown[]
19+
): OptionsInputDropdown | undefined => {
2020
return options.find(opt => String(opt.label) === String(label));
2121
};
2222

2323
export const findOptionByValue = (
2424
value: string | number | undefined,
25-
options: ListOptionsOptionType[]
26-
): ListOptionsOptionType | undefined => {
25+
options: OptionsInputDropdown[]
26+
): OptionsInputDropdown | undefined => {
2727
return options.find(opt => String(opt.value) === String(value));
2828
};

src/components/inputDropdown/hooks/__tests__/useInputDropdown.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -245,30 +245,6 @@ test('handleInputPopoverChange function', async () => {
245245
expect(result.current.inputPopoverText).toBe('newValue');
246246
});
247247

248-
test('handleInputPopoverKeyDown function', async () => {
249-
window.matchMedia = windowMatchMedia('onlyDesktop');
250-
jest.spyOn(mediaHooks, 'useMediaDevice').mockImplementation(() => DeviceBreakpointsType.DESKTOP);
251-
const mockOnBlur = jest.fn();
252-
const { result } = renderHook(() =>
253-
useInputDropdown({
254-
...mockProps,
255-
onBlur: mockOnBlur,
256-
value: 'option1',
257-
})
258-
);
259-
260-
const mockPreventDefault = jest.fn();
261-
const event = {
262-
key: 'ArrowDown',
263-
preventDefault: mockPreventDefault,
264-
} as unknown as React.KeyboardEvent<HTMLInputElement>;
265-
act(() => {
266-
result.current.handleInputPopoverKeyDown(event);
267-
});
268-
269-
expect(mockPreventDefault).toHaveBeenCalled();
270-
});
271-
272248
test('handleInputPopoverIconClick function', async () => {
273249
window.matchMedia = windowMatchMedia('onlyTablet');
274250
jest.spyOn(mediaHooks, 'useMediaDevice').mockImplementation(() => DeviceBreakpointsType.TABLET);

0 commit comments

Comments
 (0)