Skip to content

Commit

Permalink
fix(reactstrap#2664): close offcanvas when fade is false (reactstrap#…
Browse files Browse the repository at this point in the history
  • Loading branch information
illiteratewriter committed Mar 2, 2023
1 parent fa1fcc8 commit dac3587
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Offcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ class Offcanvas extends React.Component {
classNames('offcanvas-backdrop', 'show', backdropClassName),
cssModule,
)}
ref={(c) => {
this._backdrop = c;
}}
onClick={this.handleBackdropClick}
onMouseDown={this.handleBackdropMouseDown}
/>
Expand Down
17 changes: 17 additions & 0 deletions src/__tests__/Offcanvas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,23 @@ describe('Offcanvas', () => {
expect(toggle).toHaveBeenCalled();
});

it('should call toggle when clicking backdrop when fade is false', () => {
const toggle = jest.fn();
render(
<Offcanvas isOpen toggle={toggle} fade={false}>
<button id="clicker">Does Nothing</button>
</Offcanvas>,
);

user.click(screen.getByText(/does nothing/i));

expect(toggle).not.toHaveBeenCalled();

user.click(document.getElementsByClassName('offcanvas-backdrop')[0]);

expect(toggle).toHaveBeenCalled();
});

it('should destroy this._element', () => {
const { rerender } = render(
<Offcanvas isOpen toggle={toggle}>
Expand Down

0 comments on commit dac3587

Please sign in to comment.