guides-source icon indicating copy to clipboard operation
guides-source copied to clipboard

Show how to make your own input component

Open jenweber opened this issue 4 years ago • 15 comments

In Ember Octane, we have an emphasis on teaching devs how to use Ember to interact with the DOM. We should show an example of how to create a regular input, as opposed to Input.

Showing how to write a vanilla input component serves 3 purposes:

  • Teaches how to interact with the DOM
  • Allows people to clearly use and understand aria properties
  • empowers devs to understand the tradeoffs between input and Input, and make an informed decision
  • allows people to sidestep some of the event weirdness that Input has (see https://github.com/emberjs/ember.js/issues/18654)

jenweber avatar Mar 25 '20 16:03 jenweber

Note, this issue should get some learning team feedback before we move forward.

jenweber avatar Mar 25 '20 16:03 jenweber

@ember-learn/learning-core-team please review and add your comments to this issue before our next meeting, if you can find the time!

jenweber avatar Mar 25 '20 16:03 jenweber

The last time we discussed covering input some issues were raised that are still relevant, like the ergonomics of updating a value on change, hope to discuss this proposal at the weekly meeting in more detail! If we teach how to build your own "wrapper" component, meaning this wrapper component would have the change callback and expose some API to the user, I think we might end up in uncanny valley. Would it make sense to frame it as a deep dive into interacting with the DOM in general?

locks avatar Mar 25 '20 17:03 locks

The last point you made there is the framing I would like to use.

jenweber avatar Mar 25 '20 20:03 jenweber

So, one of the principles we've been moving toward is exposing the primitives, and I don't think that Input is a primitive. Rather, it's a high level convention, but it should still be based on primitives. I think having a guide that shows users how to build the conventional Input component (and all built-in components) would be a good idea.

There is the issue that the current Input is still using older conventions, and hasn't been updated quite yet. We need to finish work on {{box}} to make progress there, so it'll be a while for that. LinkTo is in a similar spot, we need to implement the Router Helpers RFC to be able to show users how to build it in a solid, conventional way.

Once that's done though, I think it would be a great guide to have. It shouldn't be the primary path for new learners, but it could be something like a tutorial: Making Ember Built-Ins from Scratch. I think this would be a great resource for intermediate learners.

pzuraq avatar Mar 26 '20 17:03 pzuraq

I think it's a bit of change we can make to the guides now that would be immediately useful. If/when we resolve the other issues, we could update the guides accordingly.

MelSumner avatar Mar 27 '20 18:03 MelSumner

@pzuraq What is {{box}}?

rajasegar avatar Mar 29 '20 01:03 rajasegar

See: https://github.com/pzuraq/ember-box

pzuraq avatar Mar 29 '20 01:03 pzuraq

@MelSumner @pzuraq I agree that there’s a lot of value here, but I do not think it’s a good idea to show how to implement the current Input and LinkTo. There be dragons in the waters for implementing it in a way that’s backwards-compatible with positional arguments as those are currently. 🐉 🌊 (I’ve spent painful time up close and personal with both Input and LinkTo in the last couple weeks, and it is appropriately gnarly given what it has to do. 😬)

A Glimmer-ready implementation, by contrast, would be very helpful—and would allow us to avoid some of the foot-guns present in implementing the primitives we have today. (There’s probably also value in showing how to do even what we have today, but I’d absolutely put that in the “Advanced” rather than “Intermediate” learning materials bucket.)

chriskrycho avatar Mar 31 '20 00:03 chriskrycho

To clarify, I would not intend to show a “faithful” Input, rather an Octane-style input without 2 way binding.

jenweber avatar Mar 31 '20 01:03 jenweber

100% to that approach! If I had more time, I'd do it myself as it's right in one of my hobby-horse spaces. 😂

chriskrycho avatar Mar 31 '20 01:03 chriskrycho

Perhaps diving into the differences between <input> and <Input> may be confusing to some. What if, instead, we describe a similar use case that comes up commonly that Ember does not attempt to solve for out of the box such as <select> dropdowns? We could cover a lot of the same content such as labels, a11y, setting the value and listening for change events etc.

hergaiety avatar Mar 31 '20 13:03 hergaiety

I would agree if beginners were the target audience, but precisely because this material is intended for an Intermediate audience I think it’s great to tackle what is unarguably already a slightly confusing point in Ember. That being said, no reason there can’t be dedicated How To/Recipe-style materials for more than one of these!

chriskrycho avatar Mar 31 '20 13:03 chriskrycho

As discussed in the learning team meeting today:

  • A place for these docs could be having a new article under "In-depth topics" in the Guides
  • Should call it MyInput or similar in order to drive home that it's not Input
  • Make good use of Zoey Says
  • Show how to build the input we want to have (Jen has a draft blog post to share)

jenweber avatar Apr 02 '20 16:04 jenweber

Hello

Did the blog post get published? I was looking into generating inputs today with Octane and have struggled to find the correct way to do it.

MatthewPringle avatar May 13 '20 19:05 MatthewPringle