Skip to content

Commit

Permalink
fix(input): update input wrapper focus on padding click
Browse files Browse the repository at this point in the history
  • Loading branch information
Satyam Chatterjee committed Aug 21, 2023
1 parent 4e515c5 commit 9f55ab1
Show file tree
Hide file tree
Showing 14 changed files with 496 additions and 234 deletions.
4 changes: 3 additions & 1 deletion core/components/atoms/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,15 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>((props, forw
);

return (
// eslint-disable-next-line
<div
data-test="DesignSystem-InputWrapper"
className={classes}
style={{ minWidth }}
onClick={() => ref.current?.focus()}
role="presentation"
role="button"
onBlur={() => setIsInputBlank(!ref.current?.value)}
tabIndex={0}
>
{inlineLabel && (
<div className="Input-inlineLabel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ exports[`Input component
<div
class="Input Input--regular"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--regular"
Expand All @@ -32,8 +33,9 @@ exports[`Input component
<div
class="Input Input--regular"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<div
class="Input-icon Input-icon--left Input-icon--inputBlank"
Expand Down Expand Up @@ -67,8 +69,9 @@ exports[`Input component
<div
class="Input Input--regular"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--regular"
Expand All @@ -91,8 +94,9 @@ exports[`Input component
<div
class="Input Input--regular"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<div
class="Input-icon Input-icon--left"
Expand Down Expand Up @@ -126,8 +130,9 @@ exports[`Input component
<div
class="Input Input--large"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--large"
Expand All @@ -149,7 +154,8 @@ exports[`Input component
<div
class="Input Input--large"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
tabindex="0"
>
<div
class="Input-inlineLabel"
Expand Down Expand Up @@ -181,8 +187,9 @@ exports[`Input component
<div
class="Input Input--regular"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--regular"
Expand All @@ -204,7 +211,8 @@ exports[`Input component
<div
class="Input Input--regular"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
tabindex="0"
>
<div
class="Input-inlineLabel"
Expand Down Expand Up @@ -236,8 +244,9 @@ exports[`Input component
<div
class="Input Input--tiny"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--tiny"
Expand All @@ -259,7 +268,8 @@ exports[`Input component
<div
class="Input Input--tiny"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
tabindex="0"
>
<div
class="Input-inlineLabel"
Expand Down Expand Up @@ -291,7 +301,8 @@ exports[`Input component
<div
class="Input Input--regular"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
tabindex="0"
>
<input
class="Input-input Input-input--regular"
Expand All @@ -313,8 +324,9 @@ exports[`Input component
<div
class="Input Input--regular"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--regular"
Expand All @@ -336,8 +348,9 @@ exports[`Input component
<div
class="Input Input--regular"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--regular"
Expand All @@ -359,8 +372,9 @@ exports[`Input component
<div
class="Input Input--regular Input--disabled"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--regular"
Expand All @@ -384,8 +398,9 @@ exports[`Input component
<div
class="Input Input--regular Input--disabled"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<div
class="Input-icon Input-icon--left"
Expand Down Expand Up @@ -420,8 +435,9 @@ exports[`Input component
<div
class="Input Input--regular Input--disabled"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--regular"
Expand All @@ -445,8 +461,9 @@ exports[`Input component
<div
class="Input Input--regular Input--disabled"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<div
class="Input-icon Input-icon--left"
Expand Down Expand Up @@ -481,8 +498,9 @@ exports[`Input component
<div
class="Input Input--regular Input--error"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--regular"
Expand All @@ -504,8 +522,9 @@ exports[`Input component
<div
class="Input Input--regular Input--error"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<div
class="Input-icon Input-icon--left Input-icon--error"
Expand Down Expand Up @@ -538,8 +557,9 @@ exports[`Input component
<div
class="Input Input--regular Input--disabled"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
class="Input-input Input-input--regular"
Expand All @@ -563,8 +583,9 @@ exports[`Input component
<div
class="Input Input--regular Input--disabled"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<div
class="Input-icon Input-icon--left"
Expand Down
9 changes: 8 additions & 1 deletion core/components/atoms/metricInput/MetricInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,14 @@ export const MetricInput = React.forwardRef<HTMLInputElement, MetricInputProps>(
const actionButtonSize = size === 'large' ? 'regular' : 'tiny';

return (
<div data-test="DesignSystem-MetricInputWrapper" className={classes} onKeyDown={onKeyDown} role="presentation">
<div
data-test="DesignSystem-MetricInputWrapper"
className={classes}
onKeyDown={onKeyDown}
role="button"
onClick={() => ref.current?.focus()}
tabIndex={0}
>
{icon && (
<Icon
data-test="DesignSystem-MetricInput--icon"
Expand Down
13 changes: 13 additions & 0 deletions core/components/atoms/metricInput/__tests__/MetricInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,16 @@ describe('MetricInput component with props showActionButton', () => {
expect(queryByTestId('DesignSystem-MetricInput--downIcon')).not.toBeInTheDocument();
});
});

describe('MetricInput component receives focus', () => {
it('when MetricInputWrapper is clicked', () => {
const { getByTestId } = render(<MetricInput />);
const metricInputWrapper = getByTestId('DesignSystem-MetricInputWrapper');
const metricInput = getByTestId('DesignSystem-MetricInput');

metricInput.focus = FunctionValue;
fireEvent.click(metricInputWrapper);

expect(metricInput.focus).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ exports[`MetricInput component
<div
class="MetricInput MetricInput--regular"
data-test="DesignSystem-MetricInputWrapper"
role="presentation"
role="button"
tabindex="0"
>
<i
class="material-icons material-icons-round Icon Icon--subtle MetricInput-icon MetricInput-icon--regular"
Expand Down Expand Up @@ -77,7 +78,8 @@ exports[`MetricInput component
<div
class="MetricInput MetricInput--regular MetricInput--error"
data-test="DesignSystem-MetricInputWrapper"
role="presentation"
role="button"
tabindex="0"
>
<i
class="material-icons material-icons-round Icon Icon--subtle MetricInput-icon MetricInput-icon--regular"
Expand Down Expand Up @@ -146,7 +148,8 @@ exports[`MetricInput component
<div
class="MetricInput MetricInput--large"
data-test="DesignSystem-MetricInputWrapper"
role="presentation"
role="button"
tabindex="0"
>
<span
class="Text Text--subtle Text--large mr-5"
Expand Down Expand Up @@ -220,7 +223,8 @@ exports[`MetricInput component
<div
class="MetricInput MetricInput--regular"
data-test="DesignSystem-MetricInputWrapper"
role="presentation"
role="button"
tabindex="0"
>
<span
class="Text Text--subtle Text--regular mr-4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ exports[`Input Mask component
<div
class="Input Input--regular"
data-test="DesignSystem-InputWrapper"
role="presentation"
role="button"
style="min-width: 256px;"
tabindex="0"
>
<input
autocomplete="off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ exports[`Pagination component
<div
class="MetricInput MetricInput--regular Pagination-MetricInput"
data-test="DesignSystem-MetricInputWrapper"
role="presentation"
role="button"
tabindex="0"
>
<input
class="MetricInput-input MetricInput-input--regular"
Expand Down
Loading

0 comments on commit 9f55ab1

Please sign in to comment.