Skip to content

Commit ca8d43a

Browse files
authored
fix(listbox): clicking disabled option no longer deselects current selection (#247)
1 parent 195ebf8 commit ca8d43a

14 files changed

Lines changed: 223 additions & 164 deletions

File tree

docs/ui/makeup-combobox/index.min.js

Lines changed: 24 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ui/makeup-combobox/index.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ui/makeup-listbox-button/index.min.js

Lines changed: 26 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ui/makeup-listbox-button/index.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ui/makeup-listbox/index.min.js

Lines changed: 24 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ui/makeup-listbox/index.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ui/makeup-listbox-button/dist/cjs/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ function _onListboxKeyDown(e) {
131131
}
132132
}
133133
function _onListboxClick(e) {
134-
if (e.target.closest("[role=option]")) {
134+
const optionEl = e.target.closest("[role=option]");
135+
if (optionEl && optionEl.getAttribute("aria-disabled") !== "true") {
135136
this.collapse();
136137
}
137138
}

packages/ui/makeup-listbox-button/dist/mjs/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ function _onListboxKeyDown(e) {
119119
}
120120
}
121121
function _onListboxClick(e) {
122-
if (e.target.closest("[role=option]")) {
122+
const optionEl = e.target.closest("[role=option]");
123+
if (optionEl && optionEl.getAttribute("aria-disabled") !== "true") {
123124
this.collapse();
124125
}
125126
}

packages/ui/makeup-listbox-button/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ function _onListboxKeyDown(e) {
139139
}
140140

141141
function _onListboxClick(e) {
142-
if (e.target.closest("[role=option]")) {
142+
const optionEl = e.target.closest("[role=option]");
143+
144+
if (optionEl && optionEl.getAttribute("aria-disabled") !== "true") {
143145
this.collapse();
144146
}
145147
}

packages/ui/makeup-listbox-button/test/index.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ test.describe("given a listbox-button for manual selection", function () {
9696
const disabledOptionEl = await contentEl.locator(".listbox-button__option[aria-disabled='true']").first();
9797
await expect(disabledOptionEl).not.toBeFocused();
9898
});
99+
100+
test("should not collapse overlay when clicking a disabled option", async function ({ page }) {
101+
const container = page.locator("#manual-selected");
102+
const btn = container.locator("button");
103+
const content = container.locator(".listbox-button__listbox");
104+
const disabledOptionEl = content.locator(".listbox-button__option[aria-disabled='true']").first();
105+
106+
await btn.click();
107+
await expect(content).toBeVisible();
108+
await disabledOptionEl.click({ force: true });
109+
await expect(content).toBeVisible();
110+
});
99111
});
100112
});
101113

@@ -188,6 +200,18 @@ test.describe("given a listbox-button for automatic selection", function () {
188200
const disabledOptionEl = await contentEl.locator(".listbox-button__option[aria-disabled='true']").first();
189201
await expect(disabledOptionEl).not.toBeFocused();
190202
});
203+
204+
test("should not collapse overlay when clicking a disabled option", async function ({ page }) {
205+
const container = page.locator("#automatic-selected");
206+
const btn = container.locator("button");
207+
const content = container.locator(".listbox-button__listbox");
208+
const disabledOptionEl = content.locator(".listbox-button__option[aria-disabled='true']").first();
209+
210+
await btn.click();
211+
await expect(content).toBeVisible();
212+
await disabledOptionEl.click({ force: true });
213+
await expect(content).toBeVisible();
214+
});
191215
});
192216
});
193217

0 commit comments

Comments
 (0)