3 ms·
...yuck. The hilarious part to me is that every single thing this does could be done in one line of an angular template with massively less typing and opportun
by agloe_dreams 3y ago
...yuck.
The hilarious part to me is that every single thing this does could be done in one line of an angular template with massively less typing and opportunity for error. just a:
<div style="display:inline-block...." [style]="{ 'backgroundColor: hsl(215, 100%, 50%)' : active }" (click)="active = !active">
Like, I know you want to create an element and blah blah...but if it takes your dev 4x longer to write it, why are you doing it? Ultimately, in the real world, all of this is devs trying to make bragging rights for reasons with no real commercial viability intended. As much as we like the idea of less JS frameworks and all that, there is a reason why every major company uses them - they allow people to make business-impacting changes and features faster.
What is really funny to me though is that it is even an awful example - you should never use a div as a button, it is an accessibility nightmare. That is telling.
- chuckadams 3y ago> you should never use a div as a button, it is an accessibility nightmare Eh, that's easily fixable with role="button" and tabindex="0". Oh, and adding a keyup handler so space and enter both click it. After that though, you have a perfectly good button. Well, minus any visual feedback that it's being clicked, but presumably you're doing some custom effect to go with the custom element... So never say "never", but yeah, use a damn <button> whenever you have the choice. The roles are there to give you an escape hatch when you don't. And sometimes buttons are actually just button-shaped links, in which case you _really_ want to use an <a> tag, because those are heinous to imitate properly.
- Py_ 3y agoExample author here. I have to say this is a bit disingenuous. You pulled the segmented button component which in a real-world environment would just be a part of a library. You should show the part where it gets used. From my experience, how this ends up playing out in a real-world environment is that these things end up getting boxed into higher-level UI libraries that turn all this stuff into quick function calls. The vast majority of devs aren't (and shouldn't be) writing their own custom components.
- chuckadams 3y ago> The vast majority of devs aren't (and shouldn't be) writing their own custom components. Component frameworks are for doing exactly that, and they generally make it pretty easy, with no manual DOM manipulation required when state changes. Rather than continue with my salty commentary, I suggest to anyone still reading to look at any other file in the example project and draw their own conclusions: https://github.com/squaresapp/rawjs-sample https://github.com/squaresapp/rawjs-sample