decidim-core 0.31.6 → 0.31.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/cells/decidim/card_metadata_cell.rb +1 -1
- data/app/cells/decidim/comments_button_cell.rb +9 -1
- data/app/cells/decidim/data_consent/category.erb +20 -33
- data/app/cells/decidim/footer_topics/show.erb +5 -8
- data/app/cells/decidim/participatory_space_dropdown_metadata/links.erb +1 -1
- data/app/cells/decidim/share_widget/qr_code_modal.erb +1 -1
- data/app/events/decidim/amendable/amendment_base_event.rb +7 -1
- data/app/helpers/decidim/menu_helper.rb +0 -2
- data/app/models/decidim/user.rb +2 -2
- data/app/packs/src/decidim/controllers/accordion/accordion.test.js +196 -42
- data/app/packs/src/decidim/controllers/accordion/controller.js +93 -17
- data/app/packs/src/decidim/controllers/dropdown/controller.js +6 -0
- data/app/packs/src/decidim/controllers/dropdown/dropdown.test.js +28 -0
- data/app/packs/src/decidim/controllers/password_toggler/controller.js +22 -1
- data/app/packs/src/decidim/controllers/password_toggler/password_toggler.test.js +11 -20
- data/app/packs/src/decidim/direct_uploads/upload_modal.js +2 -1
- data/app/packs/src/decidim/map/controller.js +10 -1
- data/app/packs/src/decidim/refactor/moved/focus_guard.js +12 -12
- data/app/packs/src/decidim/refactor/moved/focus_guard.test.js +136 -0
- data/app/packs/stylesheets/decidim/_cards.scss +1 -1
- data/app/packs/stylesheets/decidim/_cookies.scss +13 -5
- data/app/packs/stylesheets/decidim/_documents.scss +1 -1
- data/app/packs/stylesheets/decidim/_footer.scss +33 -1
- data/app/packs/stylesheets/decidim/_participatory_spaces.scss +1 -1
- data/app/presenters/decidim/footer_menu_presenter.rb +2 -4
- data/app/resolvers/decidim/meta_image_url_resolver.rb +7 -0
- data/app/views/decidim/searches/_filters.html.erb +1 -1
- data/app/views/layouts/decidim/footer/_main.html.erb +1 -1
- data/app/views/layouts/decidim/footer/_main_links.html.erb +56 -28
- data/config/locales/ar.yml +0 -20
- data/config/locales/bg.yml +0 -19
- data/config/locales/ca-IT.yml +28 -23
- data/config/locales/ca.yml +28 -23
- data/config/locales/cs.yml +13 -21
- data/config/locales/de.yml +0 -25
- data/config/locales/el.yml +0 -18
- data/config/locales/en.yml +28 -23
- data/config/locales/es-MX.yml +28 -23
- data/config/locales/es-PY.yml +28 -23
- data/config/locales/es.yml +28 -23
- data/config/locales/eu.yml +27 -24
- data/config/locales/fi-plain.yml +28 -23
- data/config/locales/fi.yml +28 -23
- data/config/locales/fr-CA.yml +7 -19
- data/config/locales/fr.yml +7 -19
- data/config/locales/gl.yml +0 -19
- data/config/locales/hu.yml +0 -17
- data/config/locales/id-ID.yml +0 -18
- data/config/locales/is-IS.yml +0 -6
- data/config/locales/it.yml +0 -17
- data/config/locales/ja.yml +28 -23
- data/config/locales/lb.yml +0 -18
- data/config/locales/lt.yml +0 -19
- data/config/locales/lv.yml +0 -18
- data/config/locales/nl.yml +0 -18
- data/config/locales/no.yml +0 -18
- data/config/locales/pl.yml +2 -19
- data/config/locales/pt-BR.yml +0 -25
- data/config/locales/pt.yml +0 -18
- data/config/locales/ro-RO.yml +0 -18
- data/config/locales/ru.yml +0 -8
- data/config/locales/sk.yml +0 -25
- data/config/locales/sv.yml +4 -25
- data/config/locales/tr-TR.yml +0 -18
- data/config/locales/uk.yml +0 -6
- data/config/locales/zh-CN.yml +0 -16
- data/config/locales/zh-TW.yml +0 -19
- data/db/migrate/20250217192438_convert_user_groups_into_users.rb +3 -2
- data/decidim-core.gemspec +3 -0
- data/lib/decidim/core/test/shared_examples/amendable/amendment_event_examples.rb +2 -2
- data/lib/decidim/core/test/shared_examples/amendable/amendment_promoted_event_examples.rb +3 -3
- data/lib/decidim/core/test/shared_examples/comments_examples.rb +26 -0
- data/lib/decidim/core/test/shared_examples/has_space_in_mcell_examples.rb +2 -1
- data/lib/decidim/core/test/shared_examples/resource_liked_event_examples.rb +3 -3
- data/lib/decidim/core/version.rb +1 -1
- data/lib/decidim/core.rb +1 -1
- data/lib/decidim/map/dynamic_map.rb +3 -1
- metadata +27 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cdd2ee47aebc30f3404fc92bd9b5954c1dfae6cdadbbd19d28d495f7939ce3d8
|
|
4
|
+
data.tar.gz: 150625ae419f2acc7f6c8068ef743c7249cee604a36a14965917e940ec5b393a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8eb46226c485aa8e26c65b6a35213d73ba3928a47f4e8262816b30be044252cbc4ecc8be8bf70377e0787e5f50eb2d848fde571c26ddb0f33ee62068a3e9d0d
|
|
7
|
+
data.tar.gz: 012df3885eb89cc74df00a64f599cae1918d4ab9d40675b1444958dbf6ba07694a3770cdc236af3628856c9e97dfc5b809fbed1ecb475fbbb93952a4067d72ee
|
|
@@ -29,7 +29,7 @@ module Decidim
|
|
|
29
29
|
return unless show_space?
|
|
30
30
|
|
|
31
31
|
{
|
|
32
|
-
text:
|
|
32
|
+
text: translated_attribute(participatory_space.title),
|
|
33
33
|
icon: resource_type_icon_key(participatory_space.class),
|
|
34
34
|
url: Decidim::ResourceLocatorPresenter.new(participatory_space).path
|
|
35
35
|
}
|
|
@@ -23,7 +23,9 @@ module Decidim
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def path
|
|
26
|
-
"#add-comment-anchor"
|
|
26
|
+
return "#add-comment-anchor" if current_user
|
|
27
|
+
|
|
28
|
+
nil
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
def text
|
|
@@ -37,5 +39,11 @@ module Decidim
|
|
|
37
39
|
def button_classes
|
|
38
40
|
"button button__sm button__transparent-secondary add-comment-mobile"
|
|
39
41
|
end
|
|
42
|
+
|
|
43
|
+
def html_options
|
|
44
|
+
return {} if current_user
|
|
45
|
+
|
|
46
|
+
{ data: { "dialog-open": "loginModal" } }
|
|
47
|
+
end
|
|
40
48
|
end
|
|
41
49
|
end
|
|
@@ -30,39 +30,26 @@
|
|
|
30
30
|
<p><%= category[:description] %></p>
|
|
31
31
|
|
|
32
32
|
<% if category[:items].present? %>
|
|
33
|
-
<
|
|
34
|
-
<
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
</
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
</div>
|
|
54
|
-
<div class="cookies__category-panel__td">
|
|
55
|
-
<%= item[:name] %>
|
|
56
|
-
</div>
|
|
57
|
-
<div class="cookies__category-panel__td">
|
|
58
|
-
<%= t("layouts.decidim.data_consent.details.items.#{item[:name]}.service") %>
|
|
59
|
-
</div>
|
|
60
|
-
<div class="cookies__category-panel__td">
|
|
61
|
-
<%= t("layouts.decidim.data_consent.details.items.#{item[:name]}.description") %>
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
<% end %>
|
|
65
|
-
</div>
|
|
33
|
+
<table>
|
|
34
|
+
<thead>
|
|
35
|
+
<tr>
|
|
36
|
+
<th><%= t("layouts.decidim.data_consent.details.columns.type") %></th>
|
|
37
|
+
<th><%= t("layouts.decidim.data_consent.details.columns.name") %></th>
|
|
38
|
+
<th><%= t("layouts.decidim.data_consent.details.columns.service") %></th>
|
|
39
|
+
<th><%= t("layouts.decidim.data_consent.details.columns.description") %></th>
|
|
40
|
+
</tr>
|
|
41
|
+
</thead>
|
|
42
|
+
<tbody>
|
|
43
|
+
<% category[:items].each do |item| %>
|
|
44
|
+
<tr>
|
|
45
|
+
<td><%= t("layouts.decidim.data_consent.details.types.#{item[:type]}") %></td>
|
|
46
|
+
<td><%= item[:name] %></td>
|
|
47
|
+
<td><%= t("layouts.decidim.data_consent.details.items.#{item[:name]}.service") %></td>
|
|
48
|
+
<td><%= t("layouts.decidim.data_consent.details.items.#{item[:name]}.description") %></td>
|
|
49
|
+
</tr>
|
|
50
|
+
<% end %>
|
|
51
|
+
</tbody>
|
|
52
|
+
</table>
|
|
66
53
|
<% end %>
|
|
67
54
|
</div>
|
|
68
55
|
</div>
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
<% end %>
|
|
7
|
-
</ul>
|
|
8
|
-
</nav>
|
|
1
|
+
<ul>
|
|
2
|
+
<% topics.each do |topic| %>
|
|
3
|
+
<%= topic_item(topic, class: "font-semibold underline") %>
|
|
4
|
+
<% end %>
|
|
5
|
+
</ul>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<div data-dialog-container>
|
|
3
3
|
<div data-dialog-title>
|
|
4
4
|
<%= icon "qr-code-line" %>
|
|
5
|
-
<h2 tabindex="-1"><%= t("decidim.share_widget.qr_code") %></h2>
|
|
5
|
+
<h2 id="dialog-title-qr-code-dialog" tabindex="-1"><%= t("decidim.share_widget.qr_code") %></h2>
|
|
6
6
|
</div>
|
|
7
7
|
<div class="content">
|
|
8
8
|
<div>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Decidim::Amendable
|
|
4
4
|
class AmendmentBaseEvent < Decidim::Events::SimpleEvent
|
|
5
5
|
i18n_attributes :amendable_path, :amendable_type, :amendable_title,
|
|
6
|
-
:emendation_path, :emendation_author_nickname, :emendation_author_path
|
|
6
|
+
:emendation_path, :emendation_author_nickname, :emendation_author_name, :emendation_author_path
|
|
7
7
|
|
|
8
8
|
def amendable_title
|
|
9
9
|
@amendable_title ||= translated_attribute(amendable_resource.title)
|
|
@@ -33,6 +33,12 @@ module Decidim::Amendable
|
|
|
33
33
|
@emendation_author_nickname ||= emendation_author.nickname
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
def emendation_author_name
|
|
37
|
+
return unless emendation_resource
|
|
38
|
+
|
|
39
|
+
@emendation_author_name ||= emendation_author.name
|
|
40
|
+
end
|
|
41
|
+
|
|
36
42
|
def emendation_author_path
|
|
37
43
|
return unless emendation_resource
|
|
38
44
|
|
|
@@ -55,10 +55,8 @@ module Decidim
|
|
|
55
55
|
@footer_menu ||= ::Decidim::FooterMenuPresenter.new(
|
|
56
56
|
:menu,
|
|
57
57
|
self,
|
|
58
|
-
element_class: "font-semibold underline",
|
|
59
58
|
active_class: "is-active",
|
|
60
59
|
role: false,
|
|
61
|
-
container_options: { class: "space-y-4 break-inside-avoid" },
|
|
62
60
|
label: t("layouts.decidim.footer.decidim_title")
|
|
63
61
|
)
|
|
64
62
|
end
|
data/app/models/decidim/user.rb
CHANGED
|
@@ -21,8 +21,8 @@ module Decidim
|
|
|
21
21
|
|
|
22
22
|
devise :invitable, :database_authenticatable, :registerable, :confirmable, :timeoutable,
|
|
23
23
|
:recoverable, :trackable, :lockable,
|
|
24
|
-
:decidim_validatable, :decidim_newsletterable,
|
|
25
|
-
:omniauthable, omniauth_providers: Decidim::OmniauthProvider.available.keys,
|
|
24
|
+
:decidim_validatable, :decidim_newsletterable,
|
|
25
|
+
:omniauthable, omniauth_providers: Decidim::OmniauthProvider.available.keys,
|
|
26
26
|
request_keys: [:env], reset_password_keys: [:decidim_organization_id, :email],
|
|
27
27
|
confirmation_keys: [:decidim_organization_id, :email]
|
|
28
28
|
devise :rememberable if Decidim.enable_remember_me
|
|
@@ -1,36 +1,44 @@
|
|
|
1
1
|
/* global jest */
|
|
2
2
|
|
|
3
3
|
import AccordionController from "src/decidim/controllers/accordion/controller";
|
|
4
|
+
import { screens } from "tailwindcss/defaultTheme"
|
|
4
5
|
|
|
5
6
|
jest.mock("a11y-accordion-component", () => ({
|
|
6
7
|
render: jest.fn(),
|
|
7
8
|
destroy: jest.fn()
|
|
8
9
|
}));
|
|
9
10
|
|
|
11
|
+
const createController = (controllerElement) => {
|
|
12
|
+
const instance = Object.create(AccordionController.prototype);
|
|
13
|
+
Reflect.defineProperty(instance, "element", {
|
|
14
|
+
get: () => controllerElement,
|
|
15
|
+
configurable: true
|
|
16
|
+
});
|
|
17
|
+
return instance;
|
|
18
|
+
};
|
|
19
|
+
|
|
10
20
|
describe("AccordionController", () => {
|
|
11
21
|
let controller = null;
|
|
12
22
|
let accordionElement = null;
|
|
13
23
|
let panel1 = null;
|
|
14
24
|
let panel2 = null;
|
|
15
25
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
const mockMatchMedia = (matchesOrPredicate = false) => {
|
|
27
|
+
window.matchMedia = jest.fn().mockImplementation((query) => {
|
|
28
|
+
const matches = typeof matchesOrPredicate === "function"
|
|
29
|
+
? matchesOrPredicate(query)
|
|
30
|
+
: matchesOrPredicate;
|
|
31
|
+
return {
|
|
32
|
+
matches,
|
|
33
|
+
media: query,
|
|
34
|
+
addEventListener: jest.fn(),
|
|
35
|
+
removeEventListener: jest.fn()
|
|
36
|
+
};
|
|
22
37
|
});
|
|
23
|
-
return instance;
|
|
24
38
|
};
|
|
25
39
|
|
|
26
40
|
beforeEach(() => {
|
|
27
|
-
|
|
28
|
-
matches: false,
|
|
29
|
-
media: query,
|
|
30
|
-
addListener: jest.fn(),
|
|
31
|
-
removeListener: jest.fn()
|
|
32
|
-
}));
|
|
33
|
-
|
|
41
|
+
mockMatchMedia(false);
|
|
34
42
|
document.body.innerHTML = `
|
|
35
43
|
<div id="test-accordion" data-controller="accordion">
|
|
36
44
|
<button id="trigger-1" data-controls="panel-1">Trigger 1</button>
|
|
@@ -39,11 +47,9 @@ describe("AccordionController", () => {
|
|
|
39
47
|
<div id="panel-2">Panel 2 Content</div>
|
|
40
48
|
</div>
|
|
41
49
|
`;
|
|
42
|
-
|
|
43
50
|
accordionElement = document.getElementById("test-accordion");
|
|
44
51
|
panel1 = document.getElementById("panel-1");
|
|
45
52
|
panel2 = document.getElementById("panel-2");
|
|
46
|
-
|
|
47
53
|
controller = createController(accordionElement);
|
|
48
54
|
});
|
|
49
55
|
|
|
@@ -56,10 +62,8 @@ describe("AccordionController", () => {
|
|
|
56
62
|
it("changes role from region to group when data-panel-role is group", () => {
|
|
57
63
|
panel1.setAttribute("role", "region");
|
|
58
64
|
panel2.setAttribute("role", "region");
|
|
59
|
-
|
|
60
65
|
accordionElement.dataset.panelRole = "group";
|
|
61
66
|
controller.fixPanelRole();
|
|
62
|
-
|
|
63
67
|
expect(panel1.getAttribute("role")).toBe("group");
|
|
64
68
|
expect(panel2.getAttribute("role")).toBe("group");
|
|
65
69
|
});
|
|
@@ -67,52 +71,202 @@ describe("AccordionController", () => {
|
|
|
67
71
|
it("removes role attribute when data-panel-role is none", () => {
|
|
68
72
|
panel1.setAttribute("role", "region");
|
|
69
73
|
panel2.setAttribute("role", "region");
|
|
70
|
-
|
|
71
74
|
accordionElement.dataset.panelRole = "none";
|
|
72
75
|
controller.fixPanelRole();
|
|
73
|
-
|
|
74
76
|
expect(panel1.getAttribute("role")).toBeNull();
|
|
75
77
|
expect(panel2.getAttribute("role")).toBeNull();
|
|
76
78
|
});
|
|
77
79
|
|
|
78
|
-
it("does nothing when data-panel-role is not set", () => {
|
|
79
|
-
panel1.setAttribute("role", "region");
|
|
80
|
-
panel2.setAttribute("role", "region");
|
|
81
|
-
|
|
82
|
-
Reflect.deleteProperty(accordionElement.dataset, "panelRole");
|
|
83
|
-
controller.fixPanelRole();
|
|
84
|
-
|
|
85
|
-
expect(panel1.getAttribute("role")).toBe("region");
|
|
86
|
-
expect(panel2.getAttribute("role")).toBe("region");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("does nothing when data-panel-role is empty", () => {
|
|
80
|
+
it("does nothing when data-panel-role is not set or empty", () => {
|
|
90
81
|
panel1.setAttribute("role", "region");
|
|
91
|
-
|
|
92
|
-
accordionElement.dataset.panelRole = "";
|
|
93
82
|
controller.fixPanelRole();
|
|
94
|
-
|
|
95
83
|
expect(panel1.getAttribute("role")).toBe("region");
|
|
96
84
|
});
|
|
97
85
|
|
|
98
86
|
it("sets custom role value when data-panel-role is set", () => {
|
|
99
87
|
panel1.setAttribute("role", "region");
|
|
100
|
-
|
|
101
88
|
accordionElement.dataset.panelRole = "navigation";
|
|
102
89
|
controller.fixPanelRole();
|
|
103
|
-
|
|
104
90
|
expect(panel1.getAttribute("role")).toBe("navigation");
|
|
105
91
|
});
|
|
106
92
|
|
|
107
93
|
it("handles nonexistent panels gracefully", () => {
|
|
108
94
|
accordionElement.dataset.panelRole = "group";
|
|
95
|
+
const trigger = document.createElement("button");
|
|
96
|
+
trigger.dataset.controls = "nonexistent-panel";
|
|
97
|
+
accordionElement.appendChild(trigger);
|
|
98
|
+
expect(() => controller.fixPanelRole()).not.toThrow();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
109
101
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
102
|
+
describe("_applyBreakpointOpenAttributes", () => {
|
|
103
|
+
beforeEach(() => {
|
|
104
|
+
controller.initialize();
|
|
105
|
+
});
|
|
113
106
|
|
|
114
|
-
|
|
107
|
+
it("removes data-open when no breakpoint matches and no original exists", () => {
|
|
108
|
+
accordionElement.innerHTML = `
|
|
109
|
+
<button data-controls="panel-1" data-open-lg="true">Trigger</button>
|
|
110
|
+
<div id="panel-1">Panel 1</div>
|
|
111
|
+
`;
|
|
112
|
+
controller._applyBreakpointOpenAttributes();
|
|
113
|
+
expect(accordionElement.querySelector("[data-controls]").hasAttribute("data-open")).toBe(false);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("sets data-open from breakpoint attribute when viewport matches", () => {
|
|
117
|
+
mockMatchMedia((query) => query === `(min-width: ${screens.lg})`);
|
|
118
|
+
accordionElement.innerHTML = `
|
|
119
|
+
<button data-controls="panel-1" data-open-lg="true">Trigger</button>
|
|
120
|
+
<div id="panel-1">Panel 1</div>
|
|
121
|
+
`;
|
|
122
|
+
controller.initialize();
|
|
123
|
+
controller._applyBreakpointOpenAttributes();
|
|
124
|
+
expect(accordionElement.querySelector("[data-controls]").getAttribute("data-open")).toBe("true");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("restores original data-open when breakpoint no longer matches", () => {
|
|
128
|
+
const lgQuery = `(min-width: ${screens.lg})`;
|
|
129
|
+
accordionElement.innerHTML = `
|
|
130
|
+
<button data-controls="panel-1" data-open="false" data-open-lg="true">Trigger</button>
|
|
131
|
+
<div id="panel-1">Panel 1</div>
|
|
132
|
+
`;
|
|
133
|
+
const trigger = accordionElement.querySelector("[data-controls]");
|
|
134
|
+
controller.initialize();
|
|
135
|
+
|
|
136
|
+
mockMatchMedia((query) => query === lgQuery);
|
|
137
|
+
controller._applyBreakpointOpenAttributes();
|
|
138
|
+
expect(trigger.getAttribute("data-open")).toBe("true");
|
|
139
|
+
|
|
140
|
+
mockMatchMedia(() => false);
|
|
141
|
+
controller._applyBreakpointOpenAttributes();
|
|
142
|
+
expect(trigger.getAttribute("data-open")).toBe("false");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("removes data-open when breakpoint stops matching and no original existed", () => {
|
|
146
|
+
const lgQuery = `(min-width: ${screens.lg})`;
|
|
147
|
+
accordionElement.innerHTML = `
|
|
148
|
+
<button data-controls="panel-1" data-open-lg="true">Trigger</button>
|
|
149
|
+
<div id="panel-1">Panel 1</div>
|
|
150
|
+
`;
|
|
151
|
+
const trigger = accordionElement.querySelector("[data-controls]");
|
|
152
|
+
controller.initialize();
|
|
153
|
+
|
|
154
|
+
mockMatchMedia((query) => query === lgQuery);
|
|
155
|
+
controller._applyBreakpointOpenAttributes();
|
|
156
|
+
expect(trigger.getAttribute("data-open")).toBe("true");
|
|
157
|
+
|
|
158
|
+
mockMatchMedia(() => false);
|
|
159
|
+
controller._applyBreakpointOpenAttributes();
|
|
160
|
+
expect(trigger.hasAttribute("data-open")).toBe(false);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("applies the last matching breakpoint when multiple match", () => {
|
|
164
|
+
mockMatchMedia((query) =>
|
|
165
|
+
query === `(min-width: ${screens.sm})` || query === `(min-width: ${screens.lg})`
|
|
166
|
+
);
|
|
167
|
+
accordionElement.innerHTML = `
|
|
168
|
+
<button data-controls="panel-1" data-open-sm="false" data-open-lg="true">Trigger</button>
|
|
169
|
+
<div id="panel-1">Panel 1</div>
|
|
170
|
+
`;
|
|
171
|
+
controller.initialize();
|
|
172
|
+
controller._applyBreakpointOpenAttributes();
|
|
173
|
+
expect(accordionElement.querySelector("[data-controls]").getAttribute("data-open")).toBe("true");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("leaves triggers without breakpoint attributes unchanged", () => {
|
|
177
|
+
controller.initialize();
|
|
178
|
+
controller._applyBreakpointOpenAttributes();
|
|
179
|
+
expect(accordionElement.querySelector("#trigger-1").hasAttribute("data-open")).toBe(false);
|
|
180
|
+
expect(accordionElement.querySelector("#trigger-2").hasAttribute("data-open")).toBe(false);
|
|
115
181
|
});
|
|
116
182
|
});
|
|
117
|
-
});
|
|
118
183
|
|
|
184
|
+
describe("_listenForBreakpointChanges", () => {
|
|
185
|
+
beforeEach(() => {
|
|
186
|
+
controller.initialize();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("registers change listeners for breakpoints with matching triggers", () => {
|
|
190
|
+
accordionElement.innerHTML = `
|
|
191
|
+
<button data-controls="panel-1" data-open-lg="true">Trigger</button>
|
|
192
|
+
<div id="panel-1">Panel 1</div>
|
|
193
|
+
`;
|
|
194
|
+
controller._listenForBreakpointChanges();
|
|
195
|
+
expect(window.matchMedia).toHaveBeenCalledWith(`(min-width: ${screens.lg})`);
|
|
196
|
+
expect(window.matchMedia.mock.results[0].value.addEventListener).toHaveBeenCalledWith("change", expect.any(Function));
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("skips breakpoints without matching triggers", () => {
|
|
200
|
+
accordionElement.innerHTML = `
|
|
201
|
+
<button data-controls="panel-1" data-open-lg="true">Trigger</button>
|
|
202
|
+
<div id="panel-1">Panel 1</div>
|
|
203
|
+
`;
|
|
204
|
+
controller._listenForBreakpointChanges();
|
|
205
|
+
expect(window.matchMedia).toHaveBeenCalledTimes(1);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("registers nothing when there are no breakpoint triggers", () => {
|
|
209
|
+
controller._listenForBreakpointChanges();
|
|
210
|
+
expect(controller._mediaQueries.length).toBe(0);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("registers listeners for multiple breakpoints", () => {
|
|
214
|
+
accordionElement.innerHTML = `
|
|
215
|
+
<button data-controls="panel-1" data-open-sm="true" data-open-lg="false">Trigger</button>
|
|
216
|
+
<div id="panel-1">Panel 1</div>
|
|
217
|
+
`;
|
|
218
|
+
controller._listenForBreakpointChanges();
|
|
219
|
+
expect(window.matchMedia).toHaveBeenCalledWith(`(min-width: ${screens.sm})`);
|
|
220
|
+
expect(window.matchMedia).toHaveBeenCalledWith(`(min-width: ${screens.lg})`);
|
|
221
|
+
expect(controller._mediaQueries.length).toBe(2);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe("_stopListeningForBreakpointChanges", () => {
|
|
226
|
+
beforeEach(() => {
|
|
227
|
+
controller.initialize();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("removes all registered change listeners", () => {
|
|
231
|
+
accordionElement.innerHTML = `
|
|
232
|
+
<button data-controls="panel-1" data-open-lg="true">Trigger</button>
|
|
233
|
+
<div id="panel-1">Panel 1</div>
|
|
234
|
+
`;
|
|
235
|
+
controller._listenForBreakpointChanges();
|
|
236
|
+
const mql = window.matchMedia.mock.results[0].value;
|
|
237
|
+
controller._stopListeningForBreakpointChanges();
|
|
238
|
+
expect(mql.removeEventListener).toHaveBeenCalledWith("change", expect.any(Function));
|
|
239
|
+
expect(controller._mediaQueries.length).toBe(0);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("does nothing when no listeners exist", () => {
|
|
243
|
+
expect(() => controller._stopListeningForBreakpointChanges()).not.toThrow();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe("connect/disconnect/reconnect with breakpoints", () => {
|
|
248
|
+
beforeEach(() => {
|
|
249
|
+
controller.initialize();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("connect applies breakpoint attributes and sets up listeners", () => {
|
|
253
|
+
const applySpy = jest.spyOn(controller, "_applyBreakpointOpenAttributes");
|
|
254
|
+
const listenSpy = jest.spyOn(controller, "_listenForBreakpointChanges");
|
|
255
|
+
controller.connect();
|
|
256
|
+
expect(applySpy).toHaveBeenCalled();
|
|
257
|
+
expect(listenSpy).toHaveBeenCalled();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("disconnect tears down breakpoint listeners", () => {
|
|
261
|
+
const spy = jest.spyOn(controller, "_stopListeningForBreakpointChanges");
|
|
262
|
+
controller.disconnect();
|
|
263
|
+
expect(spy).toHaveBeenCalled();
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("reconnect re-evaluates breakpoint attributes", () => {
|
|
267
|
+
const spy = jest.spyOn(controller, "_applyBreakpointOpenAttributes");
|
|
268
|
+
controller.reconnect({});
|
|
269
|
+
expect(spy).toHaveBeenCalled();
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
});
|
|
@@ -2,6 +2,9 @@ import { Controller } from "@hotwired/stimulus"
|
|
|
2
2
|
import Accordions from "a11y-accordion-component";
|
|
3
3
|
import { screens } from "tailwindcss/defaultTheme"
|
|
4
4
|
export default class extends Controller {
|
|
5
|
+
initialize() {
|
|
6
|
+
this._originalOpenValues = new WeakMap();
|
|
7
|
+
}
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Create accordion from a component
|
|
@@ -16,21 +19,8 @@ export default class extends Controller {
|
|
|
16
19
|
accordionOptions.isMultiSelectable = this.element.dataset.multiselectable !== "false";
|
|
17
20
|
accordionOptions.isCollapsible = this.element.dataset.collapsible !== "false";
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// Ex:
|
|
22
|
-
// data-open="false" data-open-md="true"
|
|
23
|
-
Object.keys(screens).forEach((key) => {
|
|
24
|
-
if (!this.isScreenSize(key)) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const elementsToOpen = this.element.querySelectorAll(`[data-controls][data-open-${key}]`);
|
|
29
|
-
|
|
30
|
-
elementsToOpen.forEach((elem) => {
|
|
31
|
-
(elem.dataset.open = elem.dataset[`open-${key}`.replace(/-([a-z])/g, (str) => str[1].toUpperCase())])
|
|
32
|
-
})
|
|
33
|
-
})
|
|
22
|
+
this._applyBreakpointOpenAttributes();
|
|
23
|
+
this._listenForBreakpointChanges();
|
|
34
24
|
|
|
35
25
|
if (!this.element.id) {
|
|
36
26
|
// when component has no id, we enforce to have it one
|
|
@@ -59,20 +49,106 @@ export default class extends Controller {
|
|
|
59
49
|
}
|
|
60
50
|
|
|
61
51
|
if (this.boundExpand) {
|
|
62
|
-
this.toggleButton.
|
|
52
|
+
this.toggleButton.removeEventListener("click", this.boundExpand);
|
|
63
53
|
}
|
|
54
|
+
|
|
55
|
+
this._stopListeningForBreakpointChanges();
|
|
64
56
|
}
|
|
65
57
|
|
|
66
58
|
reconnect(event) {
|
|
67
59
|
this.disconnect();
|
|
68
60
|
|
|
69
|
-
if (event.detail && event.detail.collapse) {
|
|
61
|
+
if (event && event.detail && event.detail.collapse) {
|
|
70
62
|
this.previouslyExpanded = false;
|
|
71
63
|
}
|
|
72
64
|
|
|
73
65
|
this.connect();
|
|
74
66
|
}
|
|
75
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Applies viewport-conditional data-open attributes and resets
|
|
70
|
+
* previously applied values when the viewport no longer matches.
|
|
71
|
+
*
|
|
72
|
+
* @returns {void}
|
|
73
|
+
*/
|
|
74
|
+
_applyBreakpointOpenAttributes() {
|
|
75
|
+
const controlledTriggers = new Set();
|
|
76
|
+
|
|
77
|
+
Object.keys(screens).forEach((key) => {
|
|
78
|
+
this.element.querySelectorAll(`[data-controls][data-open-${key}]`).forEach((elem) => {
|
|
79
|
+
controlledTriggers.add(elem);
|
|
80
|
+
|
|
81
|
+
if (!this._originalOpenValues.has(elem)) {
|
|
82
|
+
this._originalOpenValues.set(elem, elem.getAttribute("data-open"));
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Reset all controlled triggers to their original data-open state
|
|
88
|
+
controlledTriggers.forEach((elem) => {
|
|
89
|
+
const original = this._originalOpenValues.get(elem);
|
|
90
|
+
if (original === null) {
|
|
91
|
+
elem.removeAttribute("data-open");
|
|
92
|
+
} else {
|
|
93
|
+
elem.setAttribute("data-open", original);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Apply breakpoint-specific values for the current viewport
|
|
98
|
+
Object.keys(screens).forEach((key) => {
|
|
99
|
+
if (!this.isScreenSize(key)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.element.querySelectorAll(`[data-controls][data-open-${key}]`).forEach((elem) => {
|
|
104
|
+
elem.dataset.open = elem.getAttribute(`data-open-${key}`);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Listens for viewport changes that cross breakpoints relevant
|
|
111
|
+
* to this accordion and reconnects to keep state in sync.
|
|
112
|
+
*
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
115
|
+
_listenForBreakpointChanges() {
|
|
116
|
+
this._mediaQueries = [];
|
|
117
|
+
|
|
118
|
+
Object.keys(screens).forEach((key) => {
|
|
119
|
+
const hasRelevantTriggers = this.element.querySelector(`[data-controls][data-open-${key}]`);
|
|
120
|
+
if (!hasRelevantTriggers) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const mql = window.matchMedia(`(min-width: ${screens[key]})`);
|
|
125
|
+
const handler = () => {
|
|
126
|
+
this.reconnect({ detail: { collapse: true } });
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
if (mql.addEventListener) {
|
|
130
|
+
mql.addEventListener("change", handler);
|
|
131
|
+
} else if (mql.addListener) {
|
|
132
|
+
mql.addListener(handler);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this._mediaQueries.push({ mql, handler });
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
_stopListeningForBreakpointChanges() {
|
|
140
|
+
if (this._mediaQueries) {
|
|
141
|
+
this._mediaQueries.forEach(({ mql, handler }) => {
|
|
142
|
+
if (mql.removeEventListener) {
|
|
143
|
+
mql.removeEventListener("change", handler);
|
|
144
|
+
} else if (mql.removeListener) {
|
|
145
|
+
mql.removeListener(handler);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
this._mediaQueries = [];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
76
152
|
expandIfNeeded()
|
|
77
153
|
{
|
|
78
154
|
if (!this.toggleButton) {
|
|
@@ -47,6 +47,12 @@ export default class extends Controller {
|
|
|
47
47
|
this.element.id = `dropdown-${Math.random().toString(36).substring(7)}`
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
if (!this.element.hasAttribute("aria-expanded")) {
|
|
51
|
+
this.element.setAttribute("aria-expanded", dropdownOptions.isOpen
|
|
52
|
+
? "true"
|
|
53
|
+
: "false");
|
|
54
|
+
}
|
|
55
|
+
|
|
50
56
|
const autofocus = this.element.dataset.autofocus;
|
|
51
57
|
if (autofocus) {
|
|
52
58
|
// set the focus to some inner element, use setTimeout hack due to waiting for element to display
|