-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add isAutofocussed
and isReadOnly
to MoneyInput
and MoneyField
#362
Conversation
5a61479
to
14a978c
Compare
@@ -14,12 +15,25 @@ import currencies from './currencies.json'; | |||
import createSelectStyles from '../../internals/create-select-styles'; | |||
import vars from '../../../../materials/custom-properties.json'; | |||
|
|||
const SingleValue = ({ id, ...props }) => ( | |||
<components.SingleValue {...props}> | |||
<label htmlFor={id}>{props.children}</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap the value with a label pointing at react-select's input.
isAutofocussed
and isReadOnly
to MoneyInput
and MoneyField
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Looks good just some clarifications for me maybe.
@@ -65,7 +62,7 @@ const renderMoneyField = (props, options) => | |||
it('should render a money field', () => { | |||
const { getByLabelText } = renderMoneyField(); | |||
expect(getByLabelText('Amount')).toBeInTheDocument(); | |||
expect(getByLabelText('Currency Code')).toBeInTheDocument(); | |||
expect(getByLabelText('EUR')).toBeInTheDocument(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
expect(onBlur).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should have focus the amount input automatically when isAutofocussed is passed', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should have focussed? or should focus the?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈
onChange: PropTypes.func.isRequired, | ||
isReadOnly: PropTypes.bool, | ||
isAutofocussed: PropTypes.bool, | ||
onChange: requiredIf(PropTypes.func, props => !props.isReadOnly), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious: is this a general pattern across other inputs or what we strive for and should change elsewhere to if not already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's the same in LocalizedTextInput
, and quite a few inputs have quite a bit of copy / paste from that input
name={getCurrencyDropdownName(this.props.name)} | ||
value={option} | ||
isDisabled={this.props.isDisabled || hasNoCurrencies} | ||
isDisabled={ | ||
this.props.isDisabled || hasNoCurrencies || this.props.isReadOnly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the select rather also be in readonly mode if this component is in it? Feels a bit odd to mix states in that readonly in one becomes disabled on another.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah got it. Maybe add a comment that this mapping is due to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Apart from the typo and an potential comment about the mapping this looks good to me then.
Open question: I'm considering adding a prop, something like (isCurrencySelectionDisabled), where under this case, instead of rendering a react-select, we will render a normal label with it's for pointing at the amountInputId. That way, the user can click on Any comments @dferber90 @tdeekens |
Adds isAutofocussed and isReadOnly props. Also adds label surrounding the single value of the currency dropdown, so it can be targeted using rtl, like in the localized-text-input
This already happens (except for the label part) when you pass no currencies to I'm undecided about the API. Adding a separate prop opens up new combinations which we'd have to give answers for. What would happen for:
It seems easier to say that "currency selection will be enabled when more than one currency is passed". I don't see users wanting to dynamically switch between having currency selection enabled and disabled. It seems more like something that's decided while building a feature. So devs can then decide to omit 📞 Let's have a chat about it |
448ccd2
to
275b768
Compare
a028bcb
to
1de572c
Compare
Okay in 1de572c I removed |
I found too that the current docs are better represented by this new change, than by the current state in master 😆
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
Closes #330
Summary
isAutofocussed
prop to<MoneyInput>
and<MoneyField>
isReadOnly
prop to<MoneyInput>
and<MoneyField>
<MoneyInput>
: WrapsSingleValue
of react-select with a label pointing at the currencyCode input, so that it can be targeted using RTL.