Skip to content

Commit 85d4bd8

Browse files
authored
feat(money-input): support menu portaling (#684)
* feat(money-input): support menu portaling * feat: support menuShouldBlockSroll
1 parent 60507df commit 85d4bd8

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/components/fields/money-field/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ The amount can have an arbitrary precision. When the precision of the amount exc
5555
| `hintIcon` | `node` | - | - | - | Icon to be displayed beside the hint text. Will only get rendered when `hint` is passed as well. |
5656
| `description` | `string` or `node` | - | - | - | Provides a description for the title. |
5757
| `hasHighPrecisionBadge` | `bool` | - | - | - | Shows high precision badge in case current value uses high precision. |
58+
| `menuPortalTarget` | `HTMLElement` | - | - | - | Dom element to portal the currency select menu to |
59+
| `menuPortalZIndex` | `number` | - | - | - | z-index value for the currency select menu portal |
60+
| `menuShouldBlockScroll` | `bool` | - | - | `false` | whether the menu should block scroll while open |
5861

5962
The component further forwards all `data-` attributes to the underlying `input` component.
6063

src/components/fields/money-field/money-field.js

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class MoneyField extends React.Component {
5959
isReadOnly: PropTypes.bool,
6060
isAutofocussed: PropTypes.bool,
6161
onChange: PropTypes.func.isRequired,
62+
menuPortalTarget: PropTypes.instanceOf(PropTypes.element),
63+
menuPortalZIndex: PropTypes.number,
64+
menuShouldBlockScroll: PropTypes.bool,
6265

6366
// LabelField
6467
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
@@ -117,6 +120,9 @@ class MoneyField extends React.Component {
117120
onChange={this.props.onChange}
118121
hasError={hasError}
119122
hasHighPrecisionBadge={this.props.hasHighPrecisionBadge}
123+
menuPortalTarget={this.props.menuPortalTarget}
124+
menuPortalZIndex={this.props.menuPortalZIndex}
125+
menuShouldBlockScroll={this.props.menuShouldBlockScroll}
120126
{...filterDataAttributes(this.props)}
121127
/>
122128
<FieldErrors

src/components/inputs/money-input/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ The amount can have an arbitrary precision. When the precision of the amount exc
4848
| `hasWarning` | `bool` | - | - | - | Indicates if the input has a warning |
4949
| `horizontalConstraint` | `string` | - | `s`, `m`, `l`, `xl`, `scale` | `scale` | Horizontal size limit of the input fields. |
5050
| `hasHighPrecisionBadge` | `bool` | - | - | - | Shows high precision badge in case current value uses high precision. |
51+
| `menuPortalTarget` | `HTMLElement` | - | - | - | Dom element to portal the currency select menu to |
52+
| `menuPortalZIndex` | `number` | - | - | - | z-index value for the currency select menu portal |
53+
| `menuShouldBlockScroll` | `bool` | - | - | `false` | whether the menu should block scroll while open |
5154

5255
### Static methods
5356

src/components/inputs/money-input/money-input.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ const createCurrencySelectStyles = ({
6060
isDisabled,
6161
isReadOnly,
6262
hasFocus,
63+
menuPortalZIndex,
6364
}) => {
64-
const selectStyles = createSelectStyles({ hasWarning, hasError });
65+
const selectStyles = createSelectStyles({
66+
hasWarning,
67+
hasError,
68+
menuPortalZIndex,
69+
});
6570
return {
6671
...selectStyles,
6772
control: (base, state) => ({
@@ -389,6 +394,9 @@ class MoneyInput extends React.Component {
389394
isReadOnly: PropTypes.bool,
390395
isAutofocussed: PropTypes.bool,
391396
onChange: requiredIf(PropTypes.func, props => !props.isReadOnly),
397+
menuPortalTarget: PropTypes.instanceOf(PropTypes.element),
398+
menuPortalZIndex: PropTypes.number.isRequired,
399+
menuShouldBlockScroll: PropTypes.bool,
392400
hasError: PropTypes.bool,
393401
hasWarning: PropTypes.bool,
394402
intl: PropTypes.shape({
@@ -402,6 +410,7 @@ class MoneyInput extends React.Component {
402410
static defaultProps = {
403411
currencies: [],
404412
horizontalConstraint: 'scale',
413+
menuPortalZIndex: 1,
405414
};
406415

407416
state = {
@@ -512,6 +521,7 @@ class MoneyInput extends React.Component {
512521
isDisabled: this.props.isDisabled,
513522
isReadOnly: this.props.isReadOnly,
514523
hasFocus,
524+
menuPortalZIndex: this.props.menuPortalZIndex,
515525
});
516526
const options = this.props.currencies.map(currencyCode => ({
517527
label: currencyCode,
@@ -603,6 +613,8 @@ class MoneyInput extends React.Component {
603613
});
604614
this.setState({ currencyHasFocus: true });
605615
}}
616+
menuPortalTarget={this.props.menuPortalTarget}
617+
menuShouldBlockScroll={this.props.menuShouldBlockScroll}
606618
onBlur={() => this.setState({ currencyHasFocus: false })}
607619
onChange={this.handleCurrencyChange}
608620
data-testid="currency-dropdown"

0 commit comments

Comments
 (0)