Skip to content

Commit a10d684

Browse files
author
Sasha Kondrashov
committed
sidebar
1 parent 8650188 commit a10d684

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/modules/Sidebar/Sidebar.d.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,34 @@ export interface StrictSidebarProps {
3131
* Called before a sidebar begins to animate out.
3232
*
3333
* @param {SyntheticEvent} event - React's original SyntheticEvent.
34-
* @param {object} data - All props.
34+
* @param {object} props - All props.
35+
* @param {boolean} visible - Whether the sidebar is visible.
3536
*/
36-
onHide?: (event: React.MouseEvent<HTMLElement>, data: SidebarProps) => void
37+
onHide?: (event: React.MouseEvent<HTMLElement>, props: SidebarProps, visible: boolean) => void
3738

3839
/**
3940
* Called after a sidebar has finished animating out.
4041
*
4142
* @param {null}
42-
* @param {object} data - All props.
43+
* @param {object} props - All props.
4344
*/
44-
onHidden?: (event: React.MouseEvent<HTMLElement>, data: SidebarProps) => void
45+
onHidden?: (event: React.MouseEvent<HTMLElement>, props: SidebarProps) => void
4546

4647
/**
4748
* Called when a sidebar has finished animating in.
4849
*
4950
* @param {null}
50-
* @param {object} data - All props.
51+
* @param {object} props - All props.
5152
*/
52-
onShow?: (event: React.MouseEvent<HTMLElement>, data: SidebarProps) => void
53+
onShow?: (event: React.MouseEvent<HTMLElement>, props: SidebarProps) => void
5354

5455
/**
5556
* Called when a sidebar begins animating in.
5657
*
5758
* @param {null}
58-
* @param {object} data - All props.
59+
* @param {object} props - All props.
5960
*/
60-
onVisible?: (event: React.MouseEvent<HTMLElement>, data: SidebarProps) => void
61+
onVisible?: (event: React.MouseEvent<HTMLElement>, props: SidebarProps) => void
6162

6263
/** A sidebar can handle clicks on the passed element. */
6364
target?: Document | Window | HTMLElement | React.RefObject<HTMLElement>

src/modules/Sidebar/Sidebar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const Sidebar = React.forwardRef((props, ref) => {
7171
const callback = visible ? 'onShow' : 'onHidden'
7272

7373
resetAnimationTick()
74-
_.invoke(props, callback, null, props)
74+
_.invoke(props, callback, null, props, visible)
7575
})
7676

7777
const handleAnimationStart = useEventCallback(() => {
@@ -85,13 +85,13 @@ const Sidebar = React.forwardRef((props, ref) => {
8585
return
8686
}
8787

88-
_.invoke(props, callback, null, props)
88+
_.invoke(props, callback, null, props, visible)
8989
})
9090

9191
const handleDocumentClick = (e) => {
9292
if (!doesNodeContainClick(elementRef.current, e)) {
9393
skipNextCallback.current = true
94-
_.invoke(props, 'onHide', e, { ...props, visible: false })
94+
_.invoke(props, 'onHide', e, props, false)
9595
}
9696
}
9797

test/specs/modules/Sidebar/Sidebar-test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Sidebar', () => {
4848

4949
wrapper.setProps({ visible: false })
5050
onHide.should.have.been.calledOnce()
51-
onHide.should.have.been.calledWithMatch(null, { visible: false })
51+
onHide.should.have.been.calledWithMatch(null, {}, false)
5252
})
5353

5454
it('is called when a click on the document was done', () => {
@@ -58,7 +58,7 @@ describe('Sidebar', () => {
5858

5959
domEvent.click(document)
6060
onHide.should.have.been.calledOnce()
61-
onHide.should.have.been.calledWithMatch({}, { visible: false })
61+
onHide.should.have.been.calledWithMatch({}, {}, false)
6262
})
6363

6464
it('is called when a click on the document was done only once', () => {
@@ -68,6 +68,7 @@ describe('Sidebar', () => {
6868
domEvent.click(document)
6969
wrapper.setProps({ visible: false })
7070
onHide.should.have.been.calledOnce()
71+
onHide.should.have.been.calledWithMatch({}, {}, false)
7172
})
7273

7374
it('is not called when a click was done inside the component', () => {
@@ -101,7 +102,7 @@ describe('Sidebar', () => {
101102

102103
setTimeout(() => {
103104
onHidden.should.have.been.calledOnce()
104-
onHidden.should.have.been.calledWithMatch(null, { visible: false })
105+
onHidden.should.have.been.calledWithMatch(null, {}, false)
105106

106107
done()
107108
}, 0)
@@ -134,7 +135,7 @@ describe('Sidebar', () => {
134135

135136
wrapper.setProps({ visible: true })
136137
onVisible.should.have.been.calledOnce()
137-
onVisible.should.have.been.calledWithMatch(null, { visible: true })
138+
onVisible.should.have.been.calledWithMatch(null, {}, true)
138139
})
139140
})
140141

0 commit comments

Comments
 (0)