Skip to content

Commit 8a5ecd9

Browse files
authored
Merge pull request #1074 from Patternslib/fix-dom-hide
fix(core dom): show/hide - do not set the hidden attribute.
2 parents b4f4bef + af24138 commit 8a5ecd9

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/core/dom.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const hide = (el) => {
6666
el[DATA_STYLE_DISPLAY] = el.style.display;
6767
}
6868
el.style.display = "none";
69-
el.setAttribute("hidden", "");
7069
};
7170

7271
/**
@@ -79,7 +78,6 @@ const show = (el) => {
7978
const val = el[DATA_STYLE_DISPLAY] || null;
8079
el.style.display = val;
8180
delete el[DATA_STYLE_DISPLAY];
82-
el.removeAttribute("hidden");
8381
};
8482

8583
/**

src/core/dom.test.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,13 @@ describe("core.dom tests", () => {
122122
expect(el.style.marginTop).toBe("4em");
123123
expect(el.style.display).toBe("none");
124124
expect(el.getAttribute("style").indexOf("display") >= -1).toBeTruthy();
125-
expect(el.hasAttribute("hidden")).toBe(true);
126125

127126
dom.show(el);
128127

129128
expect(el.style.borderTop).toBe("2em");
130129
expect(el.style.marginTop).toBe("4em");
131130
expect(el.style.display).toBeFalsy();
132131
expect(el.getAttribute("style").indexOf("display") === -1).toBeTruthy();
133-
expect(el.hasAttribute("hidden")).toBe(false);
134132

135133
el.style.display = "inline";
136134
dom.hide(el);
@@ -139,14 +137,26 @@ describe("core.dom tests", () => {
139137
expect(el.style.marginTop).toBe("4em");
140138
expect(el.style.display).toBe("none");
141139
expect(el.getAttribute("style").indexOf("display") >= -1).toBeTruthy();
142-
expect(el.hasAttribute("hidden")).toBe(true);
143140

144141
dom.show(el);
145142

146143
expect(el.style.borderTop).toBe("2em");
147144
expect(el.style.marginTop).toBe("4em");
148145
expect(el.style.display).toBe("inline");
149146
expect(el.getAttribute("style").indexOf("display") >= -1).toBeTruthy();
147+
148+
done();
149+
});
150+
151+
it("most not set the hidden attribute", (done) => {
152+
// dom.hide must not set the hidden attribute due to,
153+
// https://stackoverflow.com/a/28340579/1337474
154+
// otherwise hidden input elements might not be able to be
155+
// submitted in Chrome and Safari.
156+
157+
const el = document.createElement("div");
158+
dom.hide(el);
159+
150160
expect(el.hasAttribute("hidden")).toBe(false);
151161

152162
done();

src/pat/auto-suggest/auto-suggest.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe("pat-autosuggest", function () {
6666
testutils.removeSelect2();
6767

6868
expect($el[0].getAttribute("type")).toBe("text");
69-
expect($el[0].hasAttribute("hidden")).toBe(true);
69+
expect($el[0].style.display).toBe("none");
7070
});
7171

7272
it("1.1 - An <input> element with an ajax option keeps the ajax option when turning into a select2 widget", async function () {

src/pat/date-picker/date-picker.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe("pat-date-picker", function () {
5555
expect(display_el.textContent).toBeFalsy();
5656

5757
expect(el.getAttribute("type")).toBe("date");
58-
expect(el.hasAttribute("hidden")).toBe(true);
58+
expect(el.style.display).toBe("none");
5959

6060
display_el.click();
6161

0 commit comments

Comments
 (0)