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 SelectField #114

Merged
merged 3 commits into from
Oct 2, 2018
Merged

Add SelectField #114

merged 3 commits into from
Oct 2, 2018

Conversation

dferber90
Copy link
Contributor

@dferber90 dferber90 commented Oct 1, 2018

Adds SelectField.

Needs #119 merged first.

'errors',
'isVisible',
'renderError',
// data attributes are forwarded
Copy link
Contributor

Choose a reason for hiding this comment

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

...omit(this.props, Object.keys(SelectField.propTypes)?

Copy link
Contributor

Choose a reason for hiding this comment

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

in this case doing something like const { hintIcon, badge, ..., ...rest } = this.props would have been more readable, but against our standards I suppose.

Copy link
Contributor Author

@dferber90 dferber90 Oct 1, 2018

Choose a reason for hiding this comment

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

That's pretty clever! We need to omit additional props as well like hasError (as we do not want to support it).

I think accepting any props is a bad approach as the API is not clearly defined and prop-spreading is generally hard to deal with.

To me the better approach (compared to what we're currently doing) is to be strict about the props supported in SelectInput and to remove the prop-forwarding by spread to react-select there. Then we can also be explicit about the forwarded props here.

I'd do this in a follow-up PR then though (I added it to my list).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in this case doing something like const { hintIcon, badge, ..., ...rest } = this.props would have been more readable, but against our standards I suppose.

I like the explicitness of omit over "abusing" destructuring for omitting purposes, especially as we might need to declare some variables which we then won't use (like hasError).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I now created #119 which explicitly declares all props accepted by SelectInput. I will stop the spread in SelectField (here) and forward the explicitly as well.

Then we don't need this ugly omission anymore.

@dferber90 dferber90 force-pushed the df-add-select-field branch 3 times, most recently from 56b50ca to 6d4c168 Compare October 1, 2018 18:45
@dferber90 dferber90 changed the base branch from master to df-explicitly-delcare-react-select-props October 1, 2018 18:45
@dferber90 dferber90 force-pushed the df-add-select-field branch from 6d4c168 to 3b518bf Compare October 2, 2018 08:54
Copy link
Contributor

@adnasa adnasa left a comment

Choose a reason for hiding this comment

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

!

static Placeholder = SelectInput.Placeholder;
static SelectContainer = SelectInput.SelectContainer;
static SingleValue = SelectInput.SingleValue;
static ValueContainer = SelectInput.ValueContainer;
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥

touched: (props, ...rest) =>
props.isMulti
? PropTypes.arrayOf(PropTypes.bool, ...rest)(props, ...rest)
: PropTypes.bool(props, ...rest),
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥 hot damn!

// SelectInput
'aria-label': PropTypes.string,
'aria-labelledby': PropTypes.string,
isAutofocussed: PropTypes.bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

id: do {
if (props.id) props.id;
else if (state.id) state.id;
else sequentialId();
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

@dferber90 dferber90 force-pushed the df-explicitly-delcare-react-select-props branch from cd1eda4 to ac0ddea Compare October 2, 2018 09:47
@dferber90 dferber90 changed the base branch from df-explicitly-delcare-react-select-props to master October 2, 2018 10:17
@dferber90 dferber90 force-pushed the df-add-select-field branch from 3b518bf to 44df5ee Compare October 2, 2018 10:19
@dferber90 dferber90 merged commit e6443b3 into master Oct 2, 2018
@dferber90 dferber90 deleted the df-add-select-field branch October 2, 2018 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👨‍🎨 Status: UI/UX Review Requires review from design team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants