Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 255de93

Browse files
authored
Allow text inputs to focus on mount (#2416)
1 parent 55b5335 commit 255de93

File tree

2 files changed

+9
-0
lines changed
  • assets/js/base/components

2 files changed

+9
-0
lines changed

assets/js/base/components/cart-checkout/totals/totals-coupon-code-input/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const TotalsCouponCodeInput = ( {
8585
setCouponValue( newCouponValue );
8686
} }
8787
validateOnMount={ false }
88+
focusOnMount={ true }
8889
showError={ false }
8990
/>
9091
<Button

assets/js/base/components/text-input/validated.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const ValidatedTextInput = ( {
2222
ariaDescribedBy,
2323
errorId,
2424
validateOnMount = true,
25+
focusOnMount = false,
2526
onChange,
2627
showError = true,
2728
...rest
@@ -53,6 +54,12 @@ const ValidatedTextInput = ( {
5354
}
5455
};
5556

57+
useEffect( () => {
58+
if ( focusOnMount ) {
59+
inputRef.current.focus();
60+
}
61+
}, [ focusOnMount ] );
62+
5663
useEffect( () => {
5764
if ( validateOnMount ) {
5865
validateInput();
@@ -103,6 +110,7 @@ ValidatedTextInput.propTypes = {
103110
ariaDescribedBy: PropTypes.string,
104111
errorId: PropTypes.string,
105112
validateOnMount: PropTypes.bool,
113+
focusOnMount: PropTypes.bool,
106114
showError: PropTypes.bool,
107115
};
108116

0 commit comments

Comments
 (0)