Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Fix: Allow user to provide input props #83

Merged
merged 1 commit into from
Oct 20, 2015
Merged

Conversation

joshq00
Copy link
Contributor

@joshq00 joshq00 commented Oct 17, 2015

Fixes #82

  • Update change events use event instead of value.
  • Props solely used for input components, where able, are directly passed

There are still some components where value, id, name are handled manually.

@tleunen
Copy link
Owner

tleunen commented Oct 17, 2015

Thanks @joshq00! I really appreciate the help to make react-mdl better :)

I understand we could do a cleanup in the propTypes of every component, but is some cases and especially when they are flagged "required", I think it's good to have them. It forces the user to use/set them and to know what's available on the component.

@joshq00
Copy link
Contributor Author

joshq00 commented Oct 17, 2015

I don't see any problem with keeping them in the propTypes, or documenting that all input attributes are valid props.

However, I don't think they should be required if they are not required on the native input element.

For example, if I want a text box without a label (maybe I'm just using placeholder, or putting my label elsewhere) - I have to do

<Textfield label="" />

Without doing label="", I don't just get an invariant warning... I actually get an error thrown

@tleunen
Copy link
Owner

tleunen commented Oct 17, 2015

I think it really depends. Because you know how the component is built, you know you can use a lot of props that are not described. But ideally, props should describe what you can use (or at least those who are supported and tested). A slider without the min/max value for example doesn't make a lot of sense, but because it's an input behind the scene, you know you can provide them.

In the implementation of a MDL Textfield, the label is required (for the bottom border when it's focused). So that's the reason why it's needed.

@joshq00
Copy link
Contributor Author

joshq00 commented Oct 17, 2015

I made a fiddle testing behavior with/without labels

Everything appears to be working properly without labels

@tleunen
Copy link
Owner

tleunen commented Oct 17, 2015

Yes the input still works. But it doesn't have the MDL styles. Label is required with a MDL Textfield, we cannot change that.

@joshq00
Copy link
Contributor Author

joshq00 commented Oct 17, 2015

Fair enough.

Anyhow, I didn't remove isRequired from the label property. Would you like me to add other properties?

@tleunen
Copy link
Owner

tleunen commented Oct 18, 2015

For now, because there's no documentation, I prefer keeping the propTypes because they are kind of a documentation as well.

Could you rebase instead of merge? To avoid having these merge commits ? :)
Thanks!

@joshq00
Copy link
Contributor Author

joshq00 commented Oct 18, 2015

Rebased

@tleunen
Copy link
Owner

tleunen commented Oct 18, 2015

Could you please only change the way the event is sent inside onChange?
As I said, I prefer keeping the props to serve as a documentation.

@joshq00
Copy link
Contributor Author

joshq00 commented Oct 18, 2015

I'll get those back in today or tomorrow at latest

@joshq00 joshq00 changed the title Fix: Allow user to provide input props [WIP] Fix: Allow user to provide input props Oct 19, 2015
Fixes tleunen#82

There are still some components where value, id, name are handled manually.
@joshq00 joshq00 changed the title [WIP] Fix: Allow user to provide input props Fix: Allow user to provide input props Oct 19, 2015
@joshq00
Copy link
Contributor Author

joshq00 commented Oct 19, 2015

@tleunen should be all ready now

@@ -12,7 +12,7 @@ class RadioGroup extends React.Component {
}),
container: PropTypes.string,
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
onChange: PropTypes.func,
Copy link
Owner

Choose a reason for hiding this comment

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

any reason why it's not required anymore?
Usually, React wants us to provide an onChange callback if we set a value.
This is valable for every input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly my reasoning. React already handles the checking and it's not required on the true input element. Warnings will show as they should, and the user will interact with the element like they would a normal input element.

As a user, I might not care to listen to the onChange event. I may be prototyping.

Especially in the case of the other input types, I often use defaultValue instead of value+onChange

Making the fewest assumptions about what the user "meant to do" keeps the library from limiting what they can do

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah the only reason why I see onChange not beeing required is just for prototyping because otherwise you have no way to get the value from the input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or, one could have a dom listener registered

Copy link
Owner

Choose a reason for hiding this comment

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

seriously?! Either you use react, or you don't...

I understand it's nice to be generic, but I think there's a limit to that lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not exactly. Take Facebook for example. The majority of the site was done directly mutating dom and they implemented react just for the chat section. There's a reason Facebook doesn't make assumptions about what we meant to do. I can have a full blown site that I just drop in a React component for one piece. That shouldn't break the rest of my app.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another example is if the user is looking at onClick instead of onChange. Or onTouchStart/onTouchEnd

Assumptions make an opinionated framework and, if I wanted that, I'd use ember or angular

@tleunen
Copy link
Owner

tleunen commented Oct 19, 2015

In general, yes we can set the onChange callback as optional. It helps prototyping screen. But usually people will set it anyway because we usually create controlled form. (using value + onChange).

@joshq00
Copy link
Contributor Author

joshq00 commented Oct 19, 2015

100% agree - you'll probably will want to register a handler... but you might not. there are a million edge cases where you could be accomplishing the same thing.

A use case for not having value is if I'm using a store to keep track of the freeform text instead of state.
Another use case is that, sometimes, I need to use onKeyUp instead of onChange. By requiring it, I need to do onChange={ () => {} } just to avoid all the warnings

@faergeek
Copy link
Contributor

@tleunen Take a look at this about onChange #55

@tleunen
Copy link
Owner

tleunen commented Oct 20, 2015

Yep I forgot about this valueLink. But I agree with the changes. I'll merge once I get a confirmation for the tabindex thing. I asked them on their gitter channel.

tleunen added a commit that referenced this pull request Oct 20, 2015
Fix: Allow user to provide input props
@tleunen tleunen merged commit 8e5224b into tleunen:master Oct 20, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants