Skip to content

Commit 8cd7cbc

Browse files
committed
PR feedback: make hiding the stepper a default behaviour with CSS
1 parent 7a7655b commit 8cd7cbc

File tree

6 files changed

+13
-138
lines changed

6 files changed

+13
-138
lines changed

.changeset/gold-deers-tan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'@shopify/polaris': minor
33
---
44

5-
Added `stepperShownOnInteraction` prop to `TextField` to support hiding the stepper arrows for inputs of type "number" by default and revealing them on hover and focus
5+
Made hiding the stepper arrows for inputs of type "number" and reaviling them on hover and focus the default `TextField` behaviour to mimic default browser experience

polaris-react/src/components/TextField/TextField.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ $spinner-icon-size: 12px;
5252
}
5353
}
5454

55+
.focus .Spinner {
56+
visibility: visible;
57+
}
58+
5559
.error {
5660
// stylelint-disable-next-line selector-max-class, selector-max-combinators -- generated by polaris-migrator DO NOT COPY
5761
> .Input ~ .Backdrop {
@@ -302,11 +306,16 @@ $spinner-icon-size: 12px;
302306
color: var(--p-icon);
303307
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
304308
display: flex;
309+
visibility: hidden;
305310
align-self: stretch;
306311
flex-direction: column;
307312
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
308313
width: 22px;
309314
cursor: pointer;
315+
316+
.TextField:hover & {
317+
visibility: visible;
318+
}
310319
}
311320

312321
.SpinnerIcon {

polaris-react/src/components/TextField/TextField.stories.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -587,20 +587,3 @@ export function WithInlineSuggestion() {
587587
</div>
588588
);
589589
}
590-
591-
export function WithStepperShownOnInteraction() {
592-
const [value, setValue] = useState('1');
593-
594-
const handleChange = useCallback((newValue) => setValue(newValue), []);
595-
596-
return (
597-
<TextField
598-
label="Quantity"
599-
type="number"
600-
value={value}
601-
onChange={handleChange}
602-
autoComplete="off"
603-
stepperShownOnInteraction
604-
/>
605-
);
606-
}

polaris-react/src/components/TextField/TextField.tsx

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import React, {
77
} from 'react';
88
import {CircleCancelMinor} from '@shopify/polaris-icons';
99

10-
import {useToggle} from '../../utilities/use-toggle';
1110
import {classNames, variationName} from '../../utilities/css';
1211
import {useI18n} from '../../utilities/i18n';
1312
import {useUniqueId} from '../../utilities/unique-id';
@@ -119,8 +118,6 @@ interface NonMutuallyExclusiveProps {
119118
role?: string;
120119
/** Limit increment value for numeric and date-time inputs */
121120
step?: number;
122-
/** Hide stepper by default, reveal on hover and focus */
123-
stepperShownOnInteraction?: boolean;
124121
/** Enable automatic completion by the browser. Set to "off" when you do not want the browser to fill in info */
125122
autoComplete: string;
126123
/** Mimics the behavior of the native HTML attribute, limiting the maximum value */
@@ -204,7 +201,6 @@ export function TextField({
204201
id: idProp,
205202
role,
206203
step,
207-
stepperShownOnInteraction,
208204
autoComplete,
209205
max,
210206
maxLength,
@@ -234,11 +230,6 @@ export function TextField({
234230
const [height, setHeight] = useState<number | null>(null);
235231
const [focus, setFocus] = useState(Boolean(focused));
236232
const isAfterInitial = useIsAfterInitialMount();
237-
const {
238-
value: mouseEnter,
239-
setTrue: handleMouseEnter,
240-
setFalse: handleMouseLeave,
241-
} = useToggle(false);
242233

243234
const id = useUniqueId('TextField', idProp);
244235

@@ -276,7 +267,6 @@ export function TextField({
276267
const normalizedStep = step != null ? step : 1;
277268
const normalizedMax = max != null ? max : Infinity;
278269
const normalizedMin = min != null ? min : -Infinity;
279-
const spinnerHidden = stepperShownOnInteraction && !focus && !mouseEnter;
280270

281271
const className = classNames(
282272
styles.TextField,
@@ -410,11 +400,7 @@ export function TextField({
410400
);
411401

412402
const spinnerMarkup =
413-
type === 'number' &&
414-
step !== 0 &&
415-
!disabled &&
416-
!readOnly &&
417-
!spinnerHidden ? (
403+
type === 'number' && step !== 0 && !disabled && !readOnly ? (
418404
<Spinner
419405
onClick={handleClickChild}
420406
onChange={handleNumberChange}
@@ -568,16 +554,7 @@ export function TextField({
568554
requiredIndicator={requiredIndicator}
569555
>
570556
<Connected left={connectedLeft} right={connectedRight}>
571-
<div
572-
className={className}
573-
onClick={handleClick}
574-
onMouseEnter={
575-
stepperShownOnInteraction ? handleMouseEnter : undefined
576-
}
577-
onMouseLeave={
578-
stepperShownOnInteraction ? handleMouseLeave : undefined
579-
}
580-
>
557+
<div className={className} onClick={handleClick}>
581558
{prefixMarkup}
582559
{inputMarkup}
583560
{suffixMarkup}

polaris-react/src/components/TextField/tests/TextField.test.tsx

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,99 +1116,6 @@ describe('<TextField />', () => {
11161116
expect(spy).not.toHaveBeenCalled();
11171117
});
11181118
});
1119-
1120-
describe('stepperShownOnInteraction', () => {
1121-
it('does not render spinner by default when input is not interacted with', () => {
1122-
const element = mountWithApp(
1123-
<TextField
1124-
id="MyTextField"
1125-
label="TextField"
1126-
type="number"
1127-
value="3"
1128-
autoComplete="off"
1129-
stepperShownOnInteraction
1130-
/>,
1131-
);
1132-
1133-
expect(element).not.toContainReactComponent(Spinner);
1134-
});
1135-
1136-
it('renders spinner when input is focused', () => {
1137-
const element = mountWithApp(
1138-
<TextField
1139-
id="MyTextField"
1140-
label="TextField"
1141-
type="number"
1142-
value="3"
1143-
autoComplete="off"
1144-
stepperShownOnInteraction
1145-
/>,
1146-
);
1147-
1148-
element!.find('input')!.trigger('onFocus');
1149-
1150-
expect(element).toContainReactComponent(Spinner);
1151-
});
1152-
1153-
it('does not render spinner when input is blurred', () => {
1154-
const element = mountWithApp(
1155-
<TextField
1156-
id="MyTextField"
1157-
label="TextField"
1158-
type="number"
1159-
value="3"
1160-
autoComplete="off"
1161-
stepperShownOnInteraction
1162-
/>,
1163-
);
1164-
1165-
element!.find('input')!.trigger('onFocus');
1166-
element!.find('input')!.trigger('onBlur');
1167-
1168-
expect(element).not.toContainReactComponent(Spinner);
1169-
});
1170-
1171-
it('renders spinner when `mouseenter` event is triggered', () => {
1172-
const element = mountWithApp(
1173-
<TextField
1174-
id="MyTextField"
1175-
label="TextField"
1176-
type="number"
1177-
value="3"
1178-
autoComplete="off"
1179-
stepperShownOnInteraction
1180-
/>,
1181-
);
1182-
1183-
element
1184-
.find(Connected)!
1185-
.triggerKeypath('children.props.onMouseEnter', {});
1186-
1187-
expect(element).toContainReactComponent(Spinner);
1188-
});
1189-
1190-
it('does not render spinner when `mouseleave` event is triggered', () => {
1191-
const element = mountWithApp(
1192-
<TextField
1193-
id="MyTextField"
1194-
label="TextField"
1195-
type="number"
1196-
value="3"
1197-
autoComplete="off"
1198-
stepperShownOnInteraction
1199-
/>,
1200-
);
1201-
1202-
element
1203-
.find(Connected)!
1204-
.triggerKeypath('children.props.onMouseEnter', {});
1205-
element
1206-
.find(Connected)!
1207-
.triggerKeypath('children.props.onMouseLeave', {});
1208-
1209-
expect(element).not.toContainReactComponent(Spinner);
1210-
});
1211-
});
12121119
});
12131120
});
12141121

polaris.shopify.com/content/components/selection-and-input/text-field.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ Use the placeholder to provide information that’s required to use the text fie
214214
Text fields have standard keyboard support.
215215

216216
- Merchants who rely on the keyboard expect to move focus to each text field using the <kbd>tab</kbd> key (or <kbd>shift</kbd> + <kbd>tab</kbd> when tabbing backwards)
217-
- If the `type` is set to `number`, then merchants can use the up and down arrow keys to adjust the value typed into the field
218-
- Using the `stepperShownOnInteraction` prop if the `type` is set to `number` allows to hide the stepper arrows by default and show them when the field is interacted with to mimic the default browser behaviour
217+
- If the `type` is set to `number`, then merchants can use the up and down arrow keys to adjust the value typed into the field when hovering over or focusing the field to make the arrows appear
219218
- Using the `disabled` prop will prevent the text field from receive keyboard focus or inputs
220219
- The `readOnly` prop allows focus on the text field but prevents input or editing
221220
- The `inputMode` prop can be used to bring up a relevant keyboard for merchants on mobile; it’s passed down to the input as an [`inputmode` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode)

0 commit comments

Comments
 (0)