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

Support html attributes in angle bracket components #293

Conversation

mcfiredrill
Copy link
Contributor

@mcfiredrill mcfiredrill commented Nov 19, 2019

Support for angle bracket components.
docs: #292

I know at the least ...attributes needs to be added to the template, I'm still working out if any other code can be removed or if anything else is needed.

@@ -7,6 +7,7 @@
disabled={{disabled}}
onchange={{action "change" value="target.files"}}
hidden
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can these other attributes be removed in this template since they are now passed in as regular HTML attributes?

  accept={{accept}}
  capture={{capture}}	 
  multiple={{multiple}}	
  disabled={{disabled}}	 

Or perhaps they can just be given defaults in the template and then the ...attributes will override them?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be a breaking change as we won't support curly bracket invocation syntax anymore but I think that's fine as we prepare a new major anyways. @Alonski @gilest any thoughts on that one?

Copy link
Collaborator

@gilest gilest Nov 22, 2019

Choose a reason for hiding this comment

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

The current implementation is classic component classes which support the angle bracket invocation syntax.

Important to remember that these are separate concepts in ember:

  • component type/class (classic or glimmer)
  • component invocation (curly or angle)

I think that classic components are a more flexible implementation for now since it supports both new and older ember apps.

I just read the ember-angle-bracket-invocation-polyfill docs and it seems like the polyfill itself supports ...attritubes, but using them within our own component template may mean we no longer support curly invocation.

Maybe we could move ember-angle-bracket-invocation-polyfill from devDependencies to dependencies. That might give us a hybrid solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@gilest I fear you are missing inner-html vs outer-html in your concepts. Components using inner-html (@ember/component without tagName: '') do not play well together with ...attributes cause the HTML attributes passed on invocation would be set on the the element defined by component and on the elements that have ...attributes.

E.g. if you have a component <FormElement> like this:

export default Component.extend({
  tagName: 'label',
});
<input ...attributes>

And you invoke it with <FormElement required /> the rendered HTML would be:

<label required>
  <input required>
</label>

That's not what you want in most cases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right that's an important distinction! I think tagName: '' was kind of discouraged but I've used it a lot myself.

Copy link
Collaborator

@jelhan jelhan left a comment

Choose a reason for hiding this comment

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

@mcfiredrill Thanks for starting the work on this one!

As @knownasilya pointed out here #292 (comment) the components needs to be refactored to tagless components cause otherwise HTML attributes are applied to the tag defined by them as well.

@@ -7,6 +7,7 @@
disabled={{disabled}}
onchange={{action "change" value="target.files"}}
hidden
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be a breaking change as we won't support curly bracket invocation syntax anymore but I think that's fine as we prepare a new major anyways. @Alonski @gilest any thoughts on that one?

@mcfiredrill
Copy link
Contributor Author

As @knownasilya pointed out here #292 (comment) the components needs to be refactored to tagless components cause otherwise HTML attributes are applied to the tag defined by them as well.

Sounds good. Seems like I could move the label for file-upload directly into the template.

Will need to refactor away from using attributeBindings as well.

@mcfiredrill
Copy link
Contributor Author

Sounds good. Seems like I could move the label for file-upload directly into the template.

Is it necessary for the label to wrap around the entire template, as in the current implementation?
If not, I have a feeling this check for VALID_TAGS could be removed.
https://github.com/adopted-ember-addons/ember-file-upload/blob/master/addon/components/file-upload/component.js#L160

@jelhan
Copy link
Collaborator

jelhan commented Nov 22, 2019

Is it necessary for the label to wrap around the entire template, as in the current implementation?
If not, I have a feeling this check for VALID_TAGS could be removed.
https://github.com/adopted-ember-addons/ember-file-upload/blob/master/addon/components/file-upload/component.js#L160

Oh, I wasn't aware of this. The main question seems to be: Should we support changing the tag of <label> at all? If so, that might be a show-stopper. If I didn't missed something that's not yet supported in template only components, is it?

I think we should ship valid HTML and drop that use case at all. Valid HTML would also be not wrapping input by label but assigning them to each user using for attribute on label.

@Alonski, @gilest Any thoughts?

@mcfiredrill
Copy link
Contributor Author

FWIW this is already looking to be a breaking change.

I think we should ship valid HTML and drop that use case at all. Valid HTML would also be not wrapping input by label but assigning them to each user using for attribute on label.

👍 for valid HTML.

@mcfiredrill
Copy link
Contributor Author

That said I think I don't 100% understand why the component was implemented as a label in the first place.

@gilest
Copy link
Collaborator

gilest commented Nov 22, 2019

Yeah I think the <label> element that wraps the <input> is an interactive (clickable, and maybe draggable) area in many browsers.

We should make sure we follow the spec closely here for usability and accessibility.

@gilest
Copy link
Collaborator

gilest commented Nov 22, 2019

@mcfiredrill Love the enthusiasm you're bringing 👍

But this is a pretty long-running addon, and I think supporting legacy apps and curly invocation is something we should keep doing for a while yet.

@mcfiredrill
Copy link
Contributor Author

@gilest Thanks a lot for your feedback!

I haven't looked at it much yet so I'm going to investigate what benefits using ember-angle-bracket-invocation-polyfill in dependencies would bring.

I am thinking to maybe follow this advice, and not worry about supporting html attributes for now.
#292 (comment)

I may open a new PR or just totally redo this one.

@gilest
Copy link
Collaborator

gilest commented Nov 24, 2019

@gilest Thanks a lot for your feedback!

I haven't looked at it much yet so I'm going to investigate what benefits using ember-angle-bracket-invocation-polyfill in dependencies would bring.

The polyfill is currently included in devDependencies so that we can test angle bracket invocation in our integration specs.

Moving it to dependencies would mean that users of the addon will get it too. This would allow us to use (while still supporting older versions of ember) angle bracket syntax within the addon's component templates (rather than just the tests).

I am thinking to maybe follow this advice, and not worry about supporting html attributes for now.
#292 (comment)

I may open a new PR or just totally redo this one.

Sounds like a good approach 👍

@mcfiredrill mcfiredrill changed the title [WIP] Support angle brackets [WIP] Support html attributes in angle bracket components Nov 28, 2019
@jelhan jelhan mentioned this pull request Feb 27, 2020
6 tasks
@gilest gilest mentioned this pull request Mar 12, 2020
22 tasks
@mcfiredrill mcfiredrill changed the title [WIP] Support html attributes in angle bracket components Support html attributes in angle bracket components Jun 14, 2021
@mcfiredrill
Copy link
Contributor Author

Hmm I'm confused, I see the link on github (actually a 404) saying the build failed.
But I found the build on travis just by clicking around there and it seemed to have passed:
https://travis-ci.org/github/adopted-ember-addons/ember-file-upload/builds/774490653

@gilest
Copy link
Collaborator

gilest commented Jun 16, 2021

@mcfiredrill Please push again – we're on GitHub actions now 😅

@mcfiredrill
Copy link
Contributor Author

@gilest Nice! Merged master.

@mcfiredrill
Copy link
Contributor Author

Tests are passing but I'm trying to remember exactly what I was trying to do with this PR (nearly 3 years ago!), and it looks like I wanted to re-do at least a large portion of it.

I may open a new PR or just totally redo this one

@gilest
Copy link
Collaborator

gilest commented Sep 25, 2021

Both FileDropzone and FileUpload implement splattributes since #514 which has been released as 4.1.0-beta.0

@gilest gilest closed this Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants