[4.0] Update choices.js and fix a bug with detaching#23455
[4.0] Update choices.js and fix a bug with detaching#23455Fedik wants to merge 6 commits intojoomla:4.0-devfrom
Conversation
That code is really bad, I know! But Is exposing all the wrong things that we did in the custom elements, so don't expect an update before all the custom elements are correctly implemented.
There is no rule that prohibits anyone to move nodes around the tree. Actually this behaviour reveals our bad implementation of custom elements... On the practical side, I guess the idea to transform tabs to accordion should be dropped for the production code, although it's a great accessibility win, for the reasons you also mention: future bugs (eg devs bad scripts) This PR is taking this component one step close to production but there are 2 more things that needs to be patched here:
x = document.createElement('joomla-field-fancy-select');
document.body.appendChild(x)
x.innerHTML = `<select><option value="zzzz" selected>oooo</option>`
|
|
|
||
| disconnectedCallback() { | ||
| // Destroy Choices instance, to unbind an event listeners | ||
| if (this.choicesInstance) { |
There was a problem hiding this comment.
Actually this part is correct. You need to destroy the current instance and recreate it. The missing part here is that you need a value attribute in the custom element that keeps the value (json). Also if you do it this way I guess you can skip the select element altogether and just create hidden input with the value so PHP is also happy...
There one golden rule: "Do not mess the DOM"
It not only about CE. Joomla! forms are heavy already (can have 100+ inputs), moving nodes just force a browser re-evaluate everything. Additionally Developers can have a custom scripts (even more fancy than CE), that no one know how they will behavior if you change DOM in way tabs.js doing. Instead of moving content, the
A x = document.createElement('joomla-field-fancy-select');
x.innerHTML = '<select><option value="zzzz" selected>oooo</option>';
document.body.appendChild(x);It can be change later on demand, when someone really really need it.
Injecting choicies.js (or any othe blablba.js) in to CE also wrong |
It's the second best choice since we cannot use imports which is the right way.
x = document.createElement('joomla-field-fancy-select');
x.innerHTML = '<select><option value="zzzz" selected>oooo</option>';
document.body.appendChild(x);I'm afraid that the DOM can also work the other way around (create an empty element and inject the contents later on). You can force people to do it your way but you're not complying with the specs...
Tabs shouldn't really change to accordion, that was a suggestion from the a11y group that I rushed to code. Anyways tabs already have been rewritten without this part, once the rest of the custom elements in this repo have been corrected I'll pull that code in |
I have changed, will be safe now, without injecting and without "while" loops
I am who do the specs here 😄 |
Not really, check this: joomla-cms/build/media/webcomponents/js/editor-none/editor-none.js Lines 18 to 21 in e887207 and then care only for a specific element (in that case textarea)joomla-cms/build/media/webcomponents/js/editor-none/editor-none.js Lines 98 to 111 in e887207 But anyways this is good enough for the time, let's patch the rest as well... |
| "@webcomponents/webcomponentsjs": "2.1.2", | ||
| "awesomplete": "github:LeaVerou/awesomplete", | ||
| "bootstrap": "4.1.3", | ||
| "choices.js": "^3.0.4", |
There was a problem hiding this comment.
Please update the package lock
|
@dgrammatiko but you know the cost of MutationObserver ? 😉 From my point of view it doesn't worth to bother about it 😉 |
|
this is broken now, need full redo |
|
@Fedik oops sorry, copying the js to a new PR should be easy tho |
Pull Request for Issue #23448 and #23402 (comment)
Summary of Changes
Update choices.js and fix issue caused by moving the element in DOM tree.
Before testing, run
npm installTesting Instructions
Please read #23448
@Hackwar please test it, it should fix your issue also.
Documentation Changes Required
none
side note: @dgrammatiko I would suggest to review
joomla-tab.jsbehavior, it should not move content around on resize. It mess up DOM tree, and will cause many more bugs in future.