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

implements input_* form elements #79

Merged
merged 6 commits into from
Apr 29, 2020
Merged

implements input_* form elements #79

merged 6 commits into from
Apr 29, 2020

Conversation

alexandrubagu
Copy link
Contributor

I've implemented all input_* form elements @msaraiva @zamith

@msaraiva
Copy link
Member

Hi @alexandrubagu!

Awesome job 🎉

I have a question for discussion before we merge this. As far as I could see, some of the inputs have the same properties and generate the same <input...>. The only difference is the type. Do you think it would be better to have a single component for those cases with a type property?, e.g. <Input type="date"/>, etc? Or do you feel that each one of them deserves its own component?

For the record, I'm not sure yet which approach is better so I'm trying to see the pros and cons :)

@zamith feel free to share your thoughts too.

Copy link
Contributor

@zamith zamith left a comment

Choose a reason for hiding this comment

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

Other than the comments I left, I tend to agree. We can probably abstract all of these into one Input component with a type. It will be a lot easier to maintain and the bulk of the work is already done by Phoenix.HTML.Form anyway.

We can (maybe?) still add a couple of wrappers over Input for ergonomics. For example RangeInput here has a min and max properties, which seems useful, so you don't have to send it via opts.

@msaraiva
Copy link
Member

Regarding "creating own component" vs "using a generic input". One advantage of the current implementation (having one component for each function) is that we end up with a 1:1 mapping between them, which may be more intuitive for users.

I've just noticed we've missed events for both, the inputs and the form. I believe for the inputs we have at least phx-blur, phx-focus, phx-click, phx-capture-click, phx-keydown, phx-keyup and for the form, phx-change and phx-submit.

I guess we should define them without the phx- prefix, like:

@doc "Triggered when the component loses focus"
property blur, :event

@doc "Triggered when the component receives focus"
property focus, :event

Note: It's important that we add the events explicitly, otherwise, Surface will not set the phx-target automatically and the default target will be the parent live view.

@zamith
Copy link
Contributor

zamith commented Apr 23, 2020

Agree. It was in my plans to add those. As for the 1:1 mapping, I don't think there is much difference in terms of being intuitive from:

<TextInput ...>
<PasswordInput ...>

to

<Input type="text" ...>
<Input type="password" ...>

It both makes it "simpler" in terms of maintainability for us and more closely resembles actual HTML. That being said I don't have a strong preference either way, the main reason I'm leaning towards a generic component is having less code to deal with (E.g. we want to add the events, it would be changes to one file, instead of 10)

@alexandrubagu
Copy link
Contributor Author

alexandrubagu commented Apr 23, 2020

@msaraiva @zamith I've updated the PR but I don't know how to proceed further. From my point of view I prefer to have them in separate components as they are defined in Phoenix.HTML.Form.

Another idea is to have Surface.Components.Form.GenericInput and we could use metaprogramming to generate modules with the body from GenericInput for those input elements

Copy link
Member

@msaraiva msaraiva left a comment

Choose a reason for hiding this comment

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

Hi @alexandrubagu!

Thank you so much for taking the time to work on this. I think we could start creating a generic <Input> component with a type property. We could also define the valid values like:

property type, :string, values: ["hidden", "dete", "time", ...]

if we do this we can statically validate them in the near future and editors could also use that information to provide autocomplete/suggestions.

We can also keep specific components for any of them that we feel might bring better UX, like the RangeInput. No need to remove it.

Then we can wait for some feedback to see if we need to create the others.

The others should be created on top of the generic one. That would be a perfect scenario to test the :props directive and the import_props, which have not been implemented yet but are on the roadmap.

WDYT?

import Phoenix.HTML.Form, only: [range_input: 3]
import Surface.Components.Form.Utils

alias Surface.Components.Form, warn: false
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need warn: false here since Form is being used in context get. In case you remove it and start receiving warnings, please let me know, it's a bug.

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 tests I've tried to remove warn: false and I got some warnings, so I kept them in place

@msaraiva
Copy link
Member

msaraiva commented Apr 24, 2020

@alexandrubagu I took a look at the specification of input at https://www.w3schools.com/tags/tag_input.asp

It looks like some the attributes are only applicable to some of the types. For instance, an input of type date might have attributes step, min and max but no placeholder nor maxLength. An input of type text has placeholder and maxLength but no step, min or max. That means having one component per type would give us the opportunity to improve UX later by adding those properties explicitly.

So let's move on with separate components. Thanks a lot, @alexandrubagu for your work and sorry for coming back and forth on this.

@alexandrubagu
Copy link
Contributor Author

alexandrubagu commented Apr 26, 2020

@msaraiva no problem.

I've updated the PR according to discussion from #82

@alexandrubagu alexandrubagu requested a review from msaraiva April 27, 2020 10:02
@msaraiva msaraiva merged commit fde129b into surface-ui:master Apr 29, 2020
@msaraiva
Copy link
Member

@alexandrubagu thanks! ❤️

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.

3 participants