Skip to content

Commit

Permalink
fix(chipinput): update horizontal-vertical spacing and custom icon state
Browse files Browse the repository at this point in the history
  • Loading branch information
Satyam Chatterjee authored and anuradha9712 committed Aug 2, 2023
1 parent e054ef5 commit 8d1d37e
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 163 deletions.
7 changes: 4 additions & 3 deletions core/accessibility/utils/useAccessibilityProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface IProps {
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
onKeyDown?: (event: React.KeyboardEvent<HTMLElement>) => void;
role?: AriaRoleType;
tabIndex?: number;
'aria-label'?: React.AriaAttributes['aria-label'];
}

Expand All @@ -28,13 +29,13 @@ const isKeyboardInteractionAllowed = (role: AriaRoleType, key: KeyboardEventKeyT
return allowedKeys.has(key);
};

const useAccessibilityProps = ({ onClick, onKeyDown, role = 'button', ...rest }: IProps) => {
const useAccessibilityProps = ({ onClick, onKeyDown, role = 'button', tabIndex, ...rest }: IProps) => {
return {
...(onClick
? {
onClick: onClick,
role: role,
tabIndex: 0,
tabIndex: tabIndex || 0,
'aria-label': rest['aria-label'],
onKeyDown: (e: React.SyntheticEvent<HTMLElement>) => {
if (onKeyDown) {
Expand All @@ -50,7 +51,7 @@ const useAccessibilityProps = ({ onClick, onKeyDown, role = 'button', ...rest }:
}
},
}
: { role, 'aria-label': rest['aria-label'] }),
: { role, tabIndex, 'aria-label': rest['aria-label'] }),
};
};

Expand Down
65 changes: 37 additions & 28 deletions core/components/molecules/chipInput/ChipInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const ChipInput = (props: ChipInputProps) => {
{
ChipInput: true,
['ChipInput--disabled']: disabled,
['ChipInput--withChips']: chips.length > 0,
['ChipInput--withChips']: chips && chips.length > 0,
},
className
);
Expand Down Expand Up @@ -181,7 +181,7 @@ export const ChipInput = (props: ChipInputProps) => {
type={type}
disabled={disabled}
key={index}
className="my-2 mx-2"
className="my-3 mx-2"
onClick={() => onClick && onClick(chip, index)}
onClose={() => onChipDeleteHandler(index)}
{...rest}
Expand All @@ -192,33 +192,42 @@ export const ChipInput = (props: ChipInputProps) => {
return (
/* TODO(a11y): fix accessibility */
/* eslint-disable */
<div data-test="DesignSystem-ChipInput" {...baseProps} className={ChipInputClass} onClick={onClickHandler}>
<div className="ChipInput-wrapper">
{chips && chips.length > 0 && chipComponents}
<input
data-test="DesignSystem-ChipInput--Input"
ref={inputRef}
className="ChipInput-input"
autoFocus={autoFocus}
placeholder={placeholder}
disabled={disabled}
value={inputValue}
onBlur={onBlur}
onFocus={onFocus}
onChange={onInputChangeHandler}
onKeyDown={onKeyDownHandler}
/>
{/* eslint-enable */}
<div data-test="DesignSystem-ChipInput--Border" className="ChipInput-border">
<div
data-test="DesignSystem-ChipInput"
{...baseProps}
className={ChipInputClass}
onClick={onClickHandler}
tabIndex={disabled ? -1 : 0}
>
<div className="ChipInput-wrapper">
{chips && chips.length > 0 && chipComponents}
<input
data-test="DesignSystem-ChipInput--Input"
ref={inputRef}
className="ChipInput-input"
autoFocus={autoFocus}
placeholder={chips && chips.length > 0 ? '' : placeholder}
disabled={disabled}
value={inputValue}
onBlur={onBlur}
onFocus={onFocus}
onChange={onInputChangeHandler}
onKeyDown={onKeyDownHandler}
/>
{/* eslint-enable */}
</div>
{chips.length > 0 && (
<Icon
data-test="DesignSystem-ChipInput--Icon"
name="close"
appearance={disabled ? 'disabled' : 'subtle'}
className="ChipInput-icon"
onClick={onDeleteAllHandler}
tabIndex={disabled ? -1 : 0}
/>
)}
</div>
{chips.length > 0 && (
<Icon
data-test="DesignSystem-ChipInput--Icon"
name="close"
appearance="subtle"
className="ChipInput-icon"
onClick={onDeleteAllHandler}
/>
)}
</div>
);
};
Expand Down
Loading

0 comments on commit 8d1d37e

Please sign in to comment.