- Issue created by @nod_
- 🇫🇷France nod_ Lille
At this point I'm looking for feeback on the overall approach. Chose dropbutton because it's self contained, and it's not related to forms. Other webcomponents that could be interesting: autocomplete, marchine name, vertical tabs, time diff, etc. anything self-contained that uses behaviors for init.
This makes dropbutton jquery-free as a side effect.
This makes core use the defer attribute, which will prevent a few things from working regarding aggregation at the moment, see 🐛 JavaScript aggregation should account for "async" and "defer" attributes Needs work .
- Status changed to Needs review
7 months ago 2:47pm 3 December 2023 - 🇫🇷France nod_ Lille
Accessibility is not an issue with this one. We don't use the shadow dom, the markup is stricly the same as before inside, and the drupal-dropbutton replaces a div which has no special meaning either.
- 🇮🇪Ireland markconroy
I think this is a great idea. And I love the potential for our custom components to be used in other setups, such as if we had a custom menu component, I can imagine other developers using it in their personal projects or other CMSs learning from it, using it, or adapting it to make it suit their. use case.
- 🇺🇸United States brianperry
Excited about this! So called 'html web components' (components that add behaviors to mostly existing markup and don't use the shadow dom) really seem to be catching on. Issues like this will also be super useful to demonstrate how to take advantage of existing Drupal js functionality inside a custom element. Or even better, to demonstrate the js features we don't actually need anymore.
- 🇺🇸United States cosmicdreams Minneapolis/St. Paul
Thanks @brianperry for pointing me to this issue.
In case it comes up. Yes, web components can be accessible.
https://www.erikkroes.nl/blog/accessibility/the-guide-to-accessible-web-...That's what we can do today. If the Accessibility Object Model ever lands then we'll have low-level capability to do even more.
- 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
I can't believe how simple this MR looks 😳 🤩
This makes dropbutton jquery-free as a side effect.
👏
I actually like the idea of core staking a claim to own the
drupal-
namespace for custom elements.+1
- 🇫🇷France nod_ Lille
Need help with the test failures here.
First is the test
testAdvancedCaching
I do not have a clue why this happens, fails withCaused by ErrorException: Method "IteratorAggregate::getIterator()" might add "\Traversable" as a native return type declaration in the future. Do the same in implementation "Drupal\Core\Entity\ContentEntityBase" now to avoid errors or add an explicit @return annotation to suppress this message.
And the rest of the failures happens because selenium doesn't seem to think that our custom element can be interacted with. Haven't found out why yet.
- 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
How could a
Kernel
test fail due to front-end changes?! 🤯Ah, quoting
\Drupal\Tests\views\Kernel\Plugin\RowRenderCacheTest::doTestRenderedOutput()
:$expected = $access ? ' <div class="dropbutton-wrapper" data-drupal-ajax-container><div class="dropbutton-widget"><ul class="dropbutton">' . '<li><a href="' . $node_url . '/edit?destination=/" hreflang="en">Edit</a></li>' . '<li><a href="' . $node_url . '/delete?destination=/" class="use-ajax" data-dialog-type="modal" data-dialog-options="' . Html::escape(Json::encode(['width' => 880])) . '" hreflang="en">Delete</a></li>' . '</ul></div></div>' : '';
You'll need to adjust those expectations 😅
- 🇫🇷France nod_ Lille
thanks! fixed that one.
Hopefully the selenium one won't be too bad…
- 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
I bet it's something about the selectors used in the test 🤓
- Status changed to Needs work
6 months ago 6:18pm 11 December 2023 - 🇺🇸United States smustgrave
Have not reviewed.
Seems to have some test failures though.
- 🇫🇷France pdureau Paris
Such an interesting issue! Replacing all Drupal behaviours by WebComponents looks exciting: one less Drupalism & better performance.
Is it possible to do the same with "normal" markup instead of a custom element? Leveraging the is attribute and using the web component only as an (efficient) behaviour bag:
<div is="drupal-dropbutton" class="dropbutton-wrapper dropbutton-multiple"> <div class="dropbutton-widget"> <!-- ul, li, li, li, li --> </div> </div>
Advantages:
- faster to convert the renderable once the JS is updated, just replace
data-
attributes by theis
attribute - even faster rendering because server-side goodness
- no accessibility issues because we are back to good old markup
- Selenium may prefer this one :)
Unfortunately, Safari would need a polyfill for now.
- faster to convert the renderable once the JS is updated, just replace