Skip to content

Commit ad0310d

Browse files
authored
fix: disable click event when action is disabled (#745)
* fix: disable click event when action is disabled (#725) * test: added EditorAction disable use cases
1 parent 7fd02ab commit ad0310d

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/workbench/editor/__tests__/action.test.tsx

+29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { expectFnCalled } from '@test/utils';
55
import '@testing-library/jest-dom';
66

77
import EditorAction from '../action';
8+
import { groupActionItemDisabledClassName } from '../base';
89

910
const current: IEditorActionsProps = {
1011
id: '1',
@@ -71,4 +72,32 @@ describe('The Editor Component', () => {
7172
expect(container.querySelector(`.codicon-warning`)).toBeInTheDocument();
7273
expect(container.querySelectorAll(`.codicon-warning`)!.length).toBe(8);
7374
});
75+
76+
test('The EditorAction item disabled', () => {
77+
const mockAction: IEditorActionsProps[] = Array(8)
78+
.fill(1)
79+
.map((_, index) => ({
80+
id: index.toString(),
81+
place: 'outer',
82+
icon: 'warning',
83+
}));
84+
mockAction[0].disabled = true;
85+
const mockCallback = jest.fn();
86+
87+
const { container } = render(
88+
<EditorAction
89+
isActiveGroup={true}
90+
actions={mockAction}
91+
onClickActions={jest.fn()}
92+
/>
93+
);
94+
95+
const liDom = container.querySelector(
96+
`.${groupActionItemDisabledClassName}`
97+
);
98+
99+
expect(liDom).not.toBeNull();
100+
liDom && fireEvent.click(liDom);
101+
expect(mockCallback).not.toBeCalled();
102+
});
74103
});

src/workbench/editor/action.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ function EditorAction(props: IEditorActionProps & IEditorController) {
8282
outer.map((action) => (
8383
<Tooltip key={action.id} overlay={action.title}>
8484
<div
85-
onClick={() => handleActionsClick(action)}
85+
onClick={() =>
86+
!action.disabled && handleActionsClick(action)
87+
}
8688
className={classNames(
8789
groupActionsItemClassName,
8890
action.disabled &&

0 commit comments

Comments
 (0)