PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | build/modules/block-library/accordion/view.js +25 -5 23.2.1 → trunk View file →
@@ -10,8 +10,15 @@
10 10 const accordionItem = accordionItems.find(
11 11 (item) => item.id === id
12 12 );
13 13 return accordionItem ? accordionItem.isOpen : false;
14 + },
15 + get isHidden() {
16 + const { id, accordionItems } = getContext();
17 + const accordionItem = accordionItems.find(
18 + (item) => item.id === id
19 + );
20 + return accordionItem?.isOpen ? null : "until-found";
14 21 }
15 22 },
16 23 actions: {
17 24 toggle: () => {
@@ -28,17 +35,14 @@
28 35 accordionItem.isOpen = !accordionItem.isOpen;
29 36 }
30 37 },
31 38 openPanelByHash: () => {
32 - if (hashHandled || !window.location?.hash?.length) {
39 + if (hashHandled) {
33 40 return;
34 41 }
35 42 const context = getContext();
36 43 const { id, accordionItems, autoclose } = context;
37 - const hash = decodeURIComponent(
38 - window.location.hash.slice(1)
39 - );
40 - const targetElement = window.document.getElementById(hash);
44 + const targetElement = document.querySelector(":target");
41 45 if (!targetElement) {
42 46 return;
43 47 }
44 48 const panelElement = window.document.querySelector(
@@ -62,8 +66,24 @@
62 66 }
63 67 window.setTimeout(() => {
64 68 targetElement.scrollIntoView();
65 69 }, 0);
70 + },
71 + handleBeforeMatch: () => {
72 + const context = getContext();
73 + const { id, autoclose, accordionItems } = context;
74 + const accordionItem = accordionItems.find(
75 + (item) => item.id === id
76 + );
77 + if (accordionItem) {
78 + if (autoclose) {
79 + accordionItems.forEach((item) => {
80 + item.isOpen = item.id === id;
81 + });
82 + } else {
83 + accordionItem.isOpen = true;
84 + }
85 + }
66 86 }
67 87 },
68 88 callbacks: {
69 89 initAccordionItems: () => {