Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: search box: pressing enter key clears text when clearable is true #427

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions src/components/Inputs/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import DisabledContext, {
Disabled,
} from '../../ConfigProvider/DisabledContext';
import { ShapeContext, Shape, SizeContext, Size } from '../../ConfigProvider';
import { ButtonSize, DefaultButton, SystemUIButton } from '../../Button';
import { ButtonShape, ButtonSize, SystemUIButton } from '../../Button';
import { Icon, IconName, IconSize } from '../../Icon';
import { Label, LabelSize } from '../../Label';
import {
Expand All @@ -17,6 +17,7 @@ import { FormItemInputContext } from '../../Form/Context';
import { ValidateStatus } from '../../Form/Form.types';
import { useDebounce } from '../../../hooks/useDebounce';
import {
eventKeys,
getMergedStatus,
mergeClasses,
resolveOnChange,
Expand Down Expand Up @@ -301,6 +302,15 @@ export const TextInput: FC<TextInputProps> = React.forwardRef(
}
}, [clear]);

const handleOnKeydownClear = (_event: React.KeyboardEvent) => {
if (
document.activeElement !== clearButtonRef?.current &&
_event.key === eventKeys.ENTER
) {
return;
}
handleOnClear;
};
const handleOnClear = (_event: React.MouseEvent) => {
_event.preventDefault();
_event.stopPropagation();
Expand Down Expand Up @@ -360,6 +370,15 @@ export const TextInput: FC<TextInputProps> = React.forwardRef(
return iconSize;
};

const inputShapeToButtonShapeMap = new Map<
TextInputShape | Shape,
ButtonShape
>([
[TextInputShape.Pill, ButtonShape.Round],
[TextInputShape.Rectangle, ButtonShape.Rectangle],
[TextInputShape.Underline, ButtonShape.Rectangle],
]);

const inputSizeToIconSizeMap = new Map<TextInputSize | Size, IconSize>([
[TextInputSize.Flex, getIconSize()],
[TextInputSize.Large, IconSize.Large],
Expand Down Expand Up @@ -439,6 +458,7 @@ export const TextInput: FC<TextInputProps> = React.forwardRef(
path: iconButtonProps.iconProps.path,
}}
id={iconButtonProps.id}
shape={inputShapeToButtonShapeMap.get(shape)}
size={inputSizeToButtonSizeMap.get(mergedSize)}
htmlType={iconButtonProps.htmlType}
/>
Expand Down Expand Up @@ -467,7 +487,7 @@ export const TextInput: FC<TextInputProps> = React.forwardRef(
</div>
)}
{iconButtonProps && (
<DefaultButton
<SystemUIButton
allowDisabledFocus={
iconButtonProps.allowDisabledFocus
}
Expand All @@ -478,34 +498,48 @@ export const TextInput: FC<TextInputProps> = React.forwardRef(
iconButtonProps.disabled ||
mergedDisabled
}
htmlType={iconButtonProps.htmlType}
iconProps={{
path: iconButtonProps.iconProps.path,
}}
id={iconButtonProps.id}
onClick={iconButtonProps.onClick}
shape={inputShapeToButtonShapeMap.get(
shape
)}
size={inputSizeToButtonSizeMap.get(
mergedSize
)}
htmlType={iconButtonProps.htmlType}
transparent
/>
)}
{clearable &&
clearButtonShown &&
!numbersOnly &&
htmlType !== 'number' && (
<DefaultButton
<SystemUIButton
ref={clearButtonRef}
allowDisabledFocus={allowDisabledFocus}
ariaLabel={clearButtonAriaLabel}
classNames={clearIconButtonClassNames}
disabled={mergedDisabled}
htmlType={'button'}
iconProps={{ path: IconName.mdiClose }}
onClick={
!allowDisabledFocus
? handleOnClear
: null
}
onKeyDown={
!allowDisabledFocus
? handleOnKeydownClear
: null
}
shape={inputShapeToButtonShapeMap.get(
shape
)}
size={ButtonSize.Small}
transparent
/>
)}
</div>
Expand Down
28 changes: 8 additions & 20 deletions src/components/Inputs/input.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -913,11 +913,10 @@
}

.icon-button {
background-color: transparent;
bottom: 1px;
color: var(--grey-color-60);
height: 34px;
padding: $button-padding-vertical-small $space-xxs;
height: $input-small-size;
padding: $space-xxs;
position: absolute;
transition: none;

Expand All @@ -936,7 +935,6 @@
&:active,
&:focus {
background-color: transparent;
padding: $button-padding-vertical-small $space-xxs;

svg {
color: var(--grey-color-60);
Expand All @@ -945,7 +943,6 @@

&:hover {
background-color: transparent;
padding: $button-padding-vertical-small $space-xxs;
outline-color: transparent;

svg {
Expand All @@ -955,7 +952,6 @@
}

.clear-icon-button {
background-color: transparent;
bottom: 1px;
color: var(--grey-color-60);
height: 35px;
Expand Down Expand Up @@ -1290,8 +1286,8 @@
}

.icon-button {
bottom: $space-xxxs;
height: $space-xxl;
bottom: 0;
height: 44px;

&.left-icon {
left: $space-xs;
Expand Down Expand Up @@ -1347,9 +1343,9 @@
}

.icon-button {
bottom: 1px;
height: 34px;
padding: $button-padding-vertical-small $space-xxs;
bottom: $space-xxs;
height: 28px;
padding: $space-xxs;

&.left-icon {
left: $space-xxs;
Expand Down Expand Up @@ -1469,13 +1465,6 @@

.expandable-thumb {
position: absolute;
left: -4px;
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
}

&.input-large {
.expandable-thumb {
left: -2px;
}
}

.overlay {
Expand Down Expand Up @@ -1607,8 +1596,7 @@
.icon-button {
&.focus-visible,
&:focus-visible {
background-color: var(--background-color);
padding: $button-padding-vertical-small $space-xxs;
background-color: transparent;

svg {
color: var(--grey-color-60);
Expand Down
12 changes: 6 additions & 6 deletions src/components/Select/__snapshots__/Select.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports[`Select Select is large 1`] = `
/>
<button
aria-disabled="false"
class="icon-button right-icon button button-default button-large pill-shape icon-left"
class="icon-button right-icon button button-system-ui transparent button-large icon-left"
type="button"
>
<span
Expand Down Expand Up @@ -104,7 +104,7 @@ exports[`Select Select is medium 1`] = `
/>
<button
aria-disabled="false"
class="icon-button right-icon button button-default button-medium pill-shape icon-left"
class="icon-button right-icon button button-system-ui transparent button-medium icon-left"
type="button"
>
<span
Expand Down Expand Up @@ -170,7 +170,7 @@ exports[`Select Select is pill shaped 1`] = `
/>
<button
aria-disabled="false"
class="icon-button right-icon button button-default button-medium pill-shape icon-left"
class="icon-button right-icon button button-system-ui transparent button-medium round-shape icon-left"
type="button"
>
<span
Expand Down Expand Up @@ -236,7 +236,7 @@ exports[`Select Select is rectangle shaped 1`] = `
/>
<button
aria-disabled="false"
class="icon-button right-icon button button-default button-medium pill-shape icon-left"
class="icon-button right-icon button button-system-ui transparent button-medium icon-left"
type="button"
>
<span
Expand Down Expand Up @@ -302,7 +302,7 @@ exports[`Select Select is small 1`] = `
/>
<button
aria-disabled="false"
class="icon-button right-icon button button-default button-small pill-shape icon-left"
class="icon-button right-icon button button-system-ui transparent button-small icon-left"
type="button"
>
<span
Expand Down Expand Up @@ -368,7 +368,7 @@ exports[`Select Select is underline shaped 1`] = `
/>
<button
aria-disabled="false"
class="icon-button right-icon button button-default button-medium pill-shape icon-left"
class="icon-button right-icon button button-system-ui transparent button-medium icon-left"
type="button"
>
<span
Expand Down