Skip to content

Commit ad300f5

Browse files
committed
Fix disabled classname
1 parent 605bfa0 commit ad300f5

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

packages/library/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@luciodale/react-searchable-dropdown",
3-
"version": "1.0.41",
3+
"version": "1.1.0",
44
"author": "Lucio D'Alessandro",
55
"repository": {
66
"type": "git",

packages/library/src/SearchableDropdown.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ describe("SearchableDropdown", () => {
104104
renderDropdown({ disabled: true });
105105
const input = screen.getByPlaceholderText("Pick a fruit");
106106
expect(input).toHaveProperty("disabled", true);
107+
expect(input.closest(".lda-dropdown-container")?.classList.contains("disabled")).toBe(true);
108+
});
109+
110+
it("applies classNameDisabled to the container when disabled", () => {
111+
renderDropdown({ disabled: true, classNameDisabled: "custom-disabled" });
112+
const input = screen.getByPlaceholderText("Pick a fruit");
113+
const container = input.closest(".lda-dropdown-container");
114+
expect(container?.classList.contains("custom-disabled")).toBe(true);
115+
expect(container?.classList.contains("disabled")).toBe(false);
107116
});
108117

109118
describe("a11y", () => {

packages/library/src/SearchableDropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export function SearchableDropdown<T extends TDropdownOption, G>({
213213
return (
214214
<div
215215
ref={core.refs.setReference}
216-
className={`${BASE_CLASS} ${classNameSearchableDropdownContainer} ${disabled ? "disabled" : ""}`}
216+
className={`${BASE_CLASS} ${classNameSearchableDropdownContainer} ${disabled ? classNameDisabled || "disabled" : ""}`}
217217
onKeyDown={handleKeyDown}
218218
>
219219
<input
@@ -228,7 +228,7 @@ export function SearchableDropdown<T extends TDropdownOption, G>({
228228
readOnly={disabled}
229229
disabled={disabled}
230230
placeholder={getSearchQueryLabelFromOption(value || "") || placeholder}
231-
className={`${classNameSearchQueryInput} ${disabled ? (classNameDisabled ?? "") : ""}`}
231+
className={classNameSearchQueryInput}
232232
value={core.searchQuery}
233233
onChange={core.handleOnChangeSearchQuery}
234234
data-testid={inputId ?? classNameSearchQueryInput}

packages/library/src/SearchableDropdownMulti.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type TestOverrides = {
1919
values?: string[];
2020
setValues?: (options: string[]) => void;
2121
disabled?: boolean;
22+
classNameDisabled?: string;
2223
onClearAll?: () => void;
2324
onClearOption?: (option: string) => void;
2425
};
@@ -43,6 +44,23 @@ describe("SearchableDropdownMulti", () => {
4344
expect(screen.getByPlaceholderText("Pick fruits")).toBeDefined();
4445
});
4546

47+
it("renders disabled state", () => {
48+
renderMultiDropdown({ disabled: true });
49+
const input = screen.getByPlaceholderText("Pick fruits");
50+
expect(input).toHaveProperty("disabled", true);
51+
expect(input.closest(".lda-multi-dropdown-container")?.classList.contains("disabled")).toBe(
52+
true,
53+
);
54+
});
55+
56+
it("applies classNameDisabled to the container when disabled", () => {
57+
renderMultiDropdown({ disabled: true, classNameDisabled: "custom-disabled" });
58+
const input = screen.getByPlaceholderText("Pick fruits");
59+
const container = input.closest(".lda-multi-dropdown-container");
60+
expect(container?.classList.contains("custom-disabled")).toBe(true);
61+
expect(container?.classList.contains("disabled")).toBe(false);
62+
});
63+
4664
it("opens dropdown on focus", async () => {
4765
renderMultiDropdown();
4866
await userEvent.click(screen.getByPlaceholderText("Pick fruits"));

0 commit comments

Comments
 (0)