Skip to content

Commit ee6fe3e

Browse files
author
Hector Arce De Las Heras
committed
Enhance Accessibility, Readability, and Loading State Handling
This commit introduces several changes to improve the accessibility and readability of the codebase, and to enhance the handling of the loading state of components. Changes include: Test suite structure in button.test.tsx has been refactored using describe and test blocks for improved readability and organization. Styling for the disabled state of the button in button.styled.ts has been updated to handle loading state. A disabled variable has been added to buttonStandAlone.tsx to handle the button's disabled state when it's loading. LoaderStandAlone component in loader.tsx has been modified to always return a JSX element and a visible prop has been added to control the visibility of the loader. LoaderStandaloneComponent in loaderStandAlone.tsx and ILoaderStandAlone interface in loader.ts have been updated to include a visible prop that controls the visibility of the loader. A visible field has been added to the story args for the Loader and LoaderWithCtv stories in loader.stories.tsx to control the visibility of the loader in the storybook. These changes improve the readability of the code, the accessibility of the components, and the handling of the loading state.
1 parent 5d144ba commit ee6fe3e

File tree

13 files changed

+80
-23
lines changed

13 files changed

+80
-23
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const commonArgs: IInputUnControlled = {
4949
informationAssociatedValue: { content: 'Lorem ipsum dolor sit. Lorem ipsum dolor sit amet' },
5050
iconPosition: InputIconPosition.RIGHT,
5151
icon: { icon: ICONS.ICON_PLACEHOLDER },
52+
leftIcon: { icon: ICONS.ICON_PLACEHOLDER, altText: 'icon alt text' },
53+
rightIcon: { icon: ICONS.ICON_PLACEHOLDER, altText: 'icon alt text' },
5254
secondaryLabel: labelSecondary(themeSelected),
5355
additionalInfo: additionalInfoAction(themeSelected),
5456
loader: {

src/components/input/types/input.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,13 @@ export interface IInputIcon {
156156
loading?: boolean;
157157
disabled?: boolean;
158158
// icons
159-
icon?: IElementOrIcon;
159+
rightIcon?: IElementOrIcon;
160+
leftIcon?: IElementOrIcon;
160161
iconPosition?: InputIconPosition;
162+
/**
163+
* @deprecated `icon` will be removed. Use `rightIcon` or `leftIcon` instead
164+
*/
165+
icon?: IElementOrIcon;
161166
}
162167

163168
export interface IInputLoader {
@@ -294,6 +299,8 @@ type componentPropsToOmit =
294299
| 'placeholder'
295300
| 'leftExtraStyles'
296301
| 'topExtraStyles'
302+
// uncomment when icon prop is removed
303+
// | 'iconPosition'
297304
| 'id';
298305
export interface IInputComponents
299306
extends InputAriaAttributes,
@@ -304,6 +311,7 @@ export interface IInputComponents
304311
Omit<ILabel, componentPropsToOmit>,
305312
Omit<ITitle, componentPropsToOmit>,
306313
Omit<IInputLoader, componentPropsToOmit>,
314+
// remove interface extension when icon prop is removed
307315
Omit<IInputIcon, componentPropsToOmit> {}
308316

309317
type AriaHasPopupType =
@@ -319,7 +327,10 @@ type AriaHasPopupType =
319327

320328
export interface MultipleRef {
321329
refInput?: React.MutableRefObject<HTMLInputElement>;
330+
// remove `refIcon` when icon prop is removed
322331
refIcon: React.MutableRefObject<HTMLSpanElement | undefined>;
332+
refRightIcon: React.MutableRefObject<HTMLSpanElement | undefined>;
333+
refLeftIcon: React.MutableRefObject<HTMLSpanElement | undefined>;
323334
}
324335

325336
export type FormatNumber = Intl.NumberFormatOptions & {

src/components/input/types/inputStyledPropsType.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { IElementOrIcon } from '@/components/elementOrIcon';
2+
13
import { InputStateProps, InputStylesProps } from './input';
24
import { InputIconPosition, InputState, LABEL_TYPE } from './inputTheme';
35

@@ -52,8 +54,16 @@ export type InputStyledProps = {
5254
state: InputState;
5355
styles?: InputStylesProps;
5456
cursorPointer?: string;
57+
/**
58+
* @deprecated `icon` will be removed. Use 'leftIcon` or 'rightIcon' instead
59+
*/
5560
icon?: JSX.Element | HTMLElement | React.ReactNode | string;
61+
/**
62+
* @deprecated `iconPosition` will be removed. Use 'leftIcon` or 'rightIcon' instead
63+
*/
5664
iconPosition?: InputIconPosition;
65+
leftIcon?: IElementOrIcon;
66+
rightIcon?: IElementOrIcon;
5767
labelType?: LABEL_TYPE;
5868
placeholder?: string;
5969
};

src/components/inputDate/inputDate.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ const InputDateComponent = React.forwardRef(
128128
minDate={minDate}
129129
minLength={minLength}
130130
placeholder={getPlaceholder(placeholder, state, styles[state]?.label?.type)}
131+
rightIcon={{
132+
...props.rightIcon,
133+
onClick: event => {
134+
handleShowCalendar();
135+
props.rightIcon?.onClick?.(event);
136+
},
137+
}}
131138
state={state}
132139
styles={styles}
133140
truncate={truncate}

src/components/inputDate/inputDateStandAlone.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export const InputDateStandAloneComponent = (
3434
}}
3535
id={inputId}
3636
overrideStyles={props.styles}
37+
rightIcon={{
38+
...props.rightIcon,
39+
altText: props.calendarOpen
40+
? props.configAccesibility?.closeInputIconAriaLabel
41+
: props.configAccesibility?.openInputIconAriaLabel,
42+
}}
3743
role={ROLES.COMBOBOX}
3844
variant={props.inputVariant ?? props.styles?.[props.state]?.inputVariant}
3945
/>

src/components/inputDate/stories/argtypes.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,17 @@ export const argtypes = (variants: IThemeObjectVariants, themeSelected: string):
273273
disable: true,
274274
},
275275
},
276-
icon: {
276+
rightIcon: {
277+
description:
278+
'Icon to show on the right side of the input. `altText` are not allowed here. You can set in configAccesibility prop in `iconInputOpenAriaLabel` and `iconInputCloseAriaLabel`',
279+
type: { name: 'object' },
280+
control: { type: 'object' },
277281
table: {
278-
disable: true,
282+
type: {
283+
summary: 'object',
284+
detail: 'IElementOrIcon',
285+
},
286+
category: CATEGORY_CONTROL.MODIFIERS,
279287
},
280288
},
281289
};

src/components/inputDate/stories/inputDate.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const commonArgs: IInputDate = {
5858
// initialDate: normalizeDate(new Date('01-01-2000')),
5959
// initialSecondDate: normalizeDate(new Date('05-01-2000')),
6060
defaultDate: new Date(),
61+
rightIcon: { icon: ICONS.ICON_PLACEHOLDER },
6162
closeIcon: { icon: ICONS.ICON_CLOSE },
6263
type: InputTypeType.TEXT,
6364
today: 'Today, ',

src/components/inputDate/types/inputDate.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { CustomTokenTypes, POSITIONS } from '@/types';
1111

1212
import { InputDateStylesProps } from './inputDateTheme';
1313

14+
type InputRightIconType = Omit<IElementOrIcon, 'altText'>;
15+
1416
export type SelectedDate = {
1517
startDate: Date;
1618
endDate: Date;
@@ -67,13 +69,15 @@ type propsToOmitInputBasic =
6769
| 'aria-expanded'
6870
| 'aria-haspopup'
6971
| 'formatNumber'
70-
| 'locale';
72+
| 'locale'
73+
| 'rightIcon';
7174

7275
export interface IInputDateStandAlone extends Omit<IInputStandAlone, propsToOmitInputBasic> {
7376
styles: InputDateStylesProps;
7477
// modifiers
7578
locale: string;
7679
inputVariant?: string;
80+
rightIcon?: InputRightIconType;
7781
// actionBottomSheet
7882
closeIcon?: IElementOrIcon;
7983
labelComponentType?: TextComponentType;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ describe('New Input Dropdown Component', () => {
317317
const { container, getByRole } = renderProvider(
318318
<InputDropdown
319319
{...mockProps}
320-
icon={{ icon: 'UNICORN', altText: 'Open Info', onClick: onIconClick }}
321320
optionList={{
322321
options: [
323322
{
@@ -327,10 +326,16 @@ describe('New Input Dropdown Component', () => {
327326
],
328327
}}
329328
placeholder={'placeholder'}
329+
rightIcon={{
330+
icon: 'UNICORN',
331+
altText: 'Open Info',
332+
onClick: onIconClick,
333+
}}
330334
/>
331335
);
332336

333337
const triggerButton = getByRole('button', { name: 'Open Info' });
338+
334339
fireEvent.click(triggerButton);
335340
expect(onIconClick).toHaveBeenCalled();
336341

src/components/inputDropdown/components/popoverSearchList.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ export const PopoverSearchListComponent = (
130130
},
131131
}}
132132
id={inputPopoverId}
133+
rightIcon={{
134+
...props.inputPopoverRightIcon,
135+
onClick: event => {
136+
props.onInputPopoverIconClick();
137+
props.inputPopoverRightIcon?.onClick?.(event);
138+
},
139+
}}
133140
value={props.inputPopoverValue}
134141
// The variant is the same for all the states
135142
variant={props.styles?.[props.state]?.inputVariant as string}

0 commit comments

Comments
 (0)