Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/api/index.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/api/index/handlerbase.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void

### onOutsideClick(event)

Handles window click event.
Handles outside click.

```typescript
protected onOutsideClick(event: MouseEvent): void;
Expand Down
27 changes: 27 additions & 0 deletions src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,30 @@ it("does not open when clicked on header if handler is controlled.", () => {
const handlerState: HandlerBaseState = dropdown.state();
expect(handlerState.isOpen).toBe(false);
});

it("does not open when clicked on header if dropdown is disabled.", () => {
const dropdown = mount(
<DropdownHandler disabled={true}>
<DropdownHeader id="header">Header</DropdownHeader>
<DropdownSection>Section</DropdownSection>
</DropdownHandler>
);
dropdown.find("div#header").simulate("click");

const handlerState: HandlerBaseState = dropdown.state();
expect(handlerState.isOpen).toBe(false);
});

it("does not trigger callback when clicked on header if dropdown is disabled.", () => {
const stub = jest.fn();
const dropdown = mount(
<DropdownHandler disabled={true} onToggle={stub}>
<DropdownHeader id="header">Header</DropdownHeader>
<DropdownSection>Section</DropdownSection>
</DropdownHandler>
);
dropdown.find("div#header").simulate("click");

const handlerState: HandlerBaseState = dropdown.state();
expect(stub).not.toBeCalled();
});
17 changes: 8 additions & 9 deletions src/abstractions/handler-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface HandlerBaseProps {
onOpen?: DropdownOnOpenHandler;
onClose?: DropdownOnOpenHandler;
onToggle?: DropdownOnToggleHandler;
disabled?: boolean;
toggleOnHeaderClick?: boolean;
closeOnOutsideClick?: boolean;
closeOnSectionClick?: boolean;
Expand Down Expand Up @@ -166,6 +167,10 @@ export abstract class HandlerBase<
* Triggers all callbacks: onOpen, onClose and onToggle.
*/
protected triggerCallbacks(isOpen: boolean, source: EventSource): void {
if (this.props.disabled) {
return;
}

if (isOpen && this.props.onOpen != null) {
this.props.onOpen(source);
}
Expand All @@ -181,7 +186,7 @@ export abstract class HandlerBase<
* Updates state if dropdown is not controlled.
*/
protected updateOpenState(isOpen: boolean): void {
if (this.state.isOpen !== isOpen && !this.isControlled()) {
if (this.state.isOpen !== isOpen && !this.isControlled() && !this.props.disabled) {
this.setState((state: HandlerBaseState) => ({
...state,
isOpen: isOpen
Expand Down Expand Up @@ -229,11 +234,8 @@ export abstract class HandlerBase<
return;
}

this.setState((state: HandlerBaseState) => ({
...state,
isOpen: true
}));
this.triggerCallbacks(true, EventSource.ManualTrigger);
this.updateOpenState(true);
}

/**
Expand All @@ -244,11 +246,8 @@ export abstract class HandlerBase<
return;
}

this.setState((state: HandlerBaseState) => ({
...state,
isOpen: false
}));
this.triggerCallbacks(false, EventSource.ManualTrigger);
this.updateOpenState(false);
}
//#endregion
}