Thank you, thank you, thank you for including aria and accessibility stuff. So many tutorials omit this, and it’s frustrating. Accessibility stuff should be built into codes and projects from the beginning.
Completely agree on treating the DOM as the state of the application. It's so much simpler and the available DOM APIs are powerful. My personal favorite is using the `append` method. If the appended element is new, it'll add it to the DOM. If it already exists, it'll automatically move it into the new position with no additional work needed.
I obviously had to keep going into the DOM a fair bit for this one, but case studies like this reinforce that it's the better approach for me: gomakethings.com/removing-react-dramatically-improves-performance-a-case-study/
Hi I like the way you think in terms of using vanilla web components. I used to be a Delphi developer until Delphi ver 7. I'm going to have to start watching your stuff. I need to learn to get under the hood and see how these things work. Please continue on with your components and making web web applications. You perform a good service. Clark
Thanks for sharing! Very nice. Looking forward to the next session. One thing I would like to see is the thing at the end you briefly mentioned. How would you "upgrade" this to use the dialog element instead of confirm?
I’m enjoying the series, thanks for putting these together 👍 Do you have any plans on showing option on how to encapsulate the web component code within the component itself and how that then gets consumed by the HTML? I hope this makes sense.
Thanks! Can you clarify what you mean by this: "ow to encapsulate the web component code within the component itself and how that then gets consumed by the HTML?" I'd be delighted to make a vide about if, once I better understand what you're asking.
Sure. What I see in these two videos is you’ve got the ‘pick-at-random.html’ file that contains ‘pick-at-random’ element and below that the JavaScript to make it work. How is this then reusable? For example, I’d like to use it on a different page, how would I go about doing that. Let me know if you’d like me to elaborate further.
It depends. Typically, I favor old-fashioned full page reloads. Browsers give you so much for free out-of-the-box, and I like to take advantage of that. If there's a compelling reason to use JS instead, though, I typically rely on query string parameters.
The event management feels clumsy. Do you have or could you do a video covering it in more detail? As in pros and cons compared to other methods. I'm wondering if I should change my approach.
In theory, yes, that should be enough. In reality, it's not. 😞 Many screen reader/browser combinations will NOT announce the unless you add an aria-labeledby attribute to the SVG, with a value that points to the ID of the . In the end, since you're messing with ARIA anyways, aria-label is the least complicated way to do that.
@@gomakethings Only downside of `aria-label` is it isn't translatable. For buttons and links, I stick with visually hidden text, which I'm fine appearing if CSS doesn't load. For landmark elements, I use `aria-labelledby` and point it to the corresponding section heading.
@@davidluhr Agreed! I've had accessibility experts argue both approaches to me over the years. For this particular project, I went with the easiest one to implement, but probably could have discussed the tradeoffs a bit more.
Good video. IMO a couple of mistakes though. One, the spec insists we do NOT add/remove elements in the constructor. Two, persistence (localstorage) should be handled externally to the component.
Regarding the spec: it doesn't actually say that, though most people (including me, previously) interpreted it that way. "The specification recommends that, as far as possible, developers should implement custom element setup in this callback rather than the constructor." Does setup mean add/remove elements? Attach events? Something else? It's not clear. Hawk Ticehurst has a great article on this: hawkticehurst.com/writing/you-are-probably-using-connectedcallback-wrong/ What I do know is that setting up elements in connectedCallback is a bad idea, because it can lead to the same elements being rendered multiple times if an element is, for example, moved with the append() method. You can prevent it by using special .loaded properties or whatever, but just doing it once in the constructor() is, IMO, a lot more bulletproof and simple.
Regarding localStorage, there are many ways to handle it. Outside the component (with some event to trigger the behavior) is one possible solution. Calling it a mistake is disingenous, though. What you really mean is "I would have approached this differently." That's fine, of course. The best and worst thing about JS is that there's always more than one way to do a thing. But the approach I used in this unscripted first pass isn't a mistake. It's just not what you would have done.
@@gomakethings re constructor: Spec seems very clear to me. MDN: "In the class constructor... you should not add new attributes or children". HTML Standard 4.13.2: "When authoring custom element constructors... The element must not gain attributes or children." And you can prevent double loading by using methods like replaceChidren(). Hawk's post is about event listeners and not rendering child elements.
@@gomakethings re localstorage: I'm not going to sugarcoat my take for a grown man. In my opinion, it is a mistake to couple this UI component to a persistence mechanism (you know why, I know why, everyone knows why). Granted your solution is passable as a first draft for educational purposes but it can be easily improved, and should be. In my opinion.
@@netssrmrz I'm not asking you to "sugarcoat" anything. But let's be clear: your opinion is not the same thing as fact. You disliking something doesn't make it wrong. Senior developers constantly and arrogantly insisting something non-obvious is obvious is, frankly, why I have students. I'm asking you to engage in polite discussion. If you want to do the techbro reply guy thing, this isn't the right channel for you. This is the only time I'm going to say it. Next time, you get blocked.
Thank you, thank you, thank you for including aria and accessibility stuff. So many tutorials omit this, and it’s frustrating. Accessibility stuff should be built into codes and projects from the beginning.
Couldn't agree more! It's sad that this isn't the norm in dev education.
Completely agree on treating the DOM as the state of the application. It's so much simpler and the available DOM APIs are powerful. My personal favorite is using the `append` method. If the appended element is new, it'll add it to the DOM. If it already exists, it'll automatically move it into the new position with no additional work needed.
I obviously had to keep going into the DOM a fair bit for this one, but case studies like this reinforce that it's the better approach for me: gomakethings.com/removing-react-dramatically-improves-performance-a-case-study/
Nice! You built one of those "I will select a random user from the comments below and send them a $10 gift card" thingees! Looking forward to part 3.
Part 3 is now live here: th-cam.com/video/xopiDHsNXtQ/w-d-xo.html
Hi I like the way you think in terms of using vanilla web components.
I used to be a Delphi developer until Delphi ver 7.
I'm going to have to start watching your stuff. I need to learn to get under the hood and see how these things work.
Please continue on with your components and making web web applications.
You perform a good service.
Clark
Thank you!
Thanks for sharing! Very nice. Looking forward to the next session.
One thing I would like to see is the thing at the end you briefly mentioned. How would you "upgrade" this to use the dialog element instead of confirm?
GREAT suggestion! Let me add that to the list!
Great stuff, thanks a lot!
Thank you for the kind words!
I’m enjoying the series, thanks for putting these together 👍
Do you have any plans on showing option on how to encapsulate the web component code within the component itself and how that then gets consumed by the HTML? I hope this makes sense.
Thanks! Can you clarify what you mean by this: "ow to encapsulate the web component code within the component itself and how that then gets consumed by the HTML?"
I'd be delighted to make a vide about if, once I better understand what you're asking.
Sure. What I see in these two videos is you’ve got the ‘pick-at-random.html’ file that contains ‘pick-at-random’ element and below that the JavaScript to make it work.
How is this then reusable? For example, I’d like to use it on a different page, how would I go about doing that.
Let me know if you’d like me to elaborate further.
@@NeilMerton Yep, that helps a lot. Thanks Neil!
Hey chris, how would you handle routing when working with web components?
It depends. Typically, I favor old-fashioned full page reloads. Browsers give you so much for free out-of-the-box, and I like to take advantage of that.
If there's a compelling reason to use JS instead, though, I typically rely on query string parameters.
The event management feels clumsy. Do you have or could you do a video covering it in more detail? As in pros and cons compared to other methods. I'm wondering if I should change my approach.
That's a good suggestion, thanks!
I feel you... you like native... you even not use arrow functions
Yea, I use them selectively. I find them harder to read in most cases: gomakethings.com/when-should-you-use-arrow-functions-in-vanilla-js/
would adding a title to the button svg serve as accessibility? i've heard to not mess with aria unless you really know what you're doing.
In theory, yes, that should be enough. In reality, it's not. 😞
Many screen reader/browser combinations will NOT announce the unless you add an aria-labeledby attribute to the SVG, with a value that points to the ID of the .
In the end, since you're messing with ARIA anyways, aria-label is the least complicated way to do that.
@@gomakethings Only downside of `aria-label` is it isn't translatable. For buttons and links, I stick with visually hidden text, which I'm fine appearing if CSS doesn't load. For landmark elements, I use `aria-labelledby` and point it to the corresponding section heading.
@@davidluhr Agreed! I've had accessibility experts argue both approaches to me over the years. For this particular project, I went with the easiest one to implement, but probably could have discussed the tradeoffs a bit more.
Good video. IMO a couple of mistakes though. One, the spec insists we do NOT add/remove elements in the constructor. Two, persistence (localstorage) should be handled externally to the component.
Regarding the spec: it doesn't actually say that, though most people (including me, previously) interpreted it that way.
"The specification recommends that, as far as possible, developers should implement custom element setup in this callback rather than the constructor."
Does setup mean add/remove elements? Attach events? Something else? It's not clear. Hawk Ticehurst has a great article on this: hawkticehurst.com/writing/you-are-probably-using-connectedcallback-wrong/
What I do know is that setting up elements in connectedCallback is a bad idea, because it can lead to the same elements being rendered multiple times if an element is, for example, moved with the append() method. You can prevent it by using special .loaded properties or whatever, but just doing it once in the constructor() is, IMO, a lot more bulletproof and simple.
Regarding localStorage, there are many ways to handle it. Outside the component (with some event to trigger the behavior) is one possible solution.
Calling it a mistake is disingenous, though. What you really mean is "I would have approached this differently."
That's fine, of course. The best and worst thing about JS is that there's always more than one way to do a thing.
But the approach I used in this unscripted first pass isn't a mistake. It's just not what you would have done.
@@gomakethings re constructor: Spec seems very clear to me. MDN: "In the class constructor... you should not add new attributes or children". HTML Standard 4.13.2: "When authoring custom element constructors... The element must not gain attributes or children." And you can prevent double loading by using methods like replaceChidren(). Hawk's post is about event listeners and not rendering child elements.
@@gomakethings re localstorage: I'm not going to sugarcoat my take for a grown man. In my opinion, it is a mistake to couple this UI component to a persistence mechanism (you know why, I know why, everyone knows why). Granted your solution is passable as a first draft for educational purposes but it can be easily improved, and should be. In my opinion.
@@netssrmrz I'm not asking you to "sugarcoat" anything.
But let's be clear: your opinion is not the same thing as fact. You disliking something doesn't make it wrong.
Senior developers constantly and arrogantly insisting something non-obvious is obvious is, frankly, why I have students.
I'm asking you to engage in polite discussion. If you want to do the techbro reply guy thing, this isn't the right channel for you.
This is the only time I'm going to say it. Next time, you get blocked.