Skip to content

Commit 51d34b0

Browse files
authored
Confirm dialog provider fix (#1111)
* Add test * Fix regression
1 parent 23bfdce commit 51d34b0

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/components/button/Button.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ function Button({
3030
className,
3131
rel,
3232
setProps,
33+
// onClick prop needs to be overridable for dcc.ConfirmDialog
34+
// eslint-disable-next-line react/prop-types
35+
onClick,
3336
...otherProps
3437
}) {
3538
const incrementClicks = () => {
@@ -38,7 +41,7 @@ function Button({
3841
}
3942
};
4043
const useLink = href && !disabled;
41-
otherProps[useLink ? 'preOnClick' : 'onClick'] = incrementClicks;
44+
otherProps[useLink ? 'preOnClick' : 'onClick'] = onClick || incrementClicks;
4245

4346
if (useLink) {
4447
// react-bootstrap strips out target prop if tag isn't an anchor element,

src/components/button/__tests__/Button.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,18 @@ describe('Button', () => {
135135
await user.click(button.getByText('Clickable'));
136136
expect(mockEventListener.mock.calls).toHaveLength(0);
137137
});
138+
139+
test('onClick can be overridden', async () => {
140+
const user = userEvent.setup();
141+
const mockOnClick = jest.fn();
142+
const button = render(
143+
<Button href="/relative" onClick={mockOnClick}>
144+
Clickable
145+
</Button>
146+
);
147+
148+
expect(mockOnClick.mock.calls).toHaveLength(0);
149+
await user.click(button.getByText('Clickable'));
150+
expect(mockOnClick.mock.calls).toHaveLength(1);
151+
});
138152
});

uv.lock

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

0 commit comments

Comments
 (0)