Skip to content
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

Merged
merged 8 commits into from
Dec 27, 2018

Conversation

montezume
Copy link
Contributor

@montezume montezume commented Dec 23, 2018

Closes #330

Summary

  • Adds isAutofocussed prop to <MoneyInput> and <MoneyField>
  • Adds isReadOnly prop to <MoneyInput> and <MoneyField>
  • <MoneyInput>: Wraps SingleValue of react-select with a label pointing at the currencyCode input, so that it can be targeted using RTL.

@@ -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>
Copy link
Contributor Author

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.

@montezume montezume changed the title feat: improve money-input Add isAutofocussed and isReadOnly to MoneyInput and MoneyField Dec 23, 2018
Copy link
Contributor

@tdeekens tdeekens left a 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();
Copy link
Contributor

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', () => {
Copy link
Contributor

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?

Copy link
Contributor Author

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),
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tdeekens react-select doesn't seem to have a readonly prop ref

Copy link
Contributor

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?

Copy link
Contributor

@tdeekens tdeekens left a 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.

@montezume
Copy link
Contributor Author

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 EUR, and focus on the input-able input. Same as with LocalizedTextInput. This would be helpful for #339.

Any comments @dferber90 @tdeekens

@dferber90
Copy link
Contributor

dferber90 commented Dec 24, 2018

This already happens (except for the label part) when you pass no currencies to MoneyInput. It might make sense to also disable the selection it in case only one currency is passed.

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:

  • isCurrencySelectionDisabled: false and currencies: []
  • isCurrencySelectionDisabled: false and currencies: ['EUR']
  • isCurrencySelectionDisabled: false and currencies: undefined
  • isCurrencySelectionDisabled: true and currencies: ['EUR']

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 currencies. Even if it's needed dynamically they could do currencies={isCurrencySelectionDisabled ? [] : ['EUR', 'USD']}.

📞 Let's have a chat about it

@montezume
Copy link
Contributor Author

Okay in 1de572c I removed isCurrencySelectDisabled, and reworked the component to display a label with an htmlFor pointing at the amount input id if there are no currencies.

@montezume
Copy link
Contributor Author

I found too that the current docs are better represented by this new change, than by the current state in master 😆

List of possible currencies. When not provided or empty, the component renders a label with the value's currency instead of a dropdown```

Copy link
Contributor

@dferber90 dferber90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@montezume montezume merged commit e500cfe into master Dec 27, 2018
@montezume montezume deleted the ml-money-input-fixe branch December 27, 2018 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants