@@ -71,8 +71,8 @@ export interface MenuProps
7171 * - For the true case use `onShow`.
7272 * NOTE: `onShow` behaves slightly differently. `onVisibilityChange` would trigger
7373 * with `isVisible=true` only when transitioning from hidden to shown, this meant
74- * if the same context menu was re-triggered from a new position the event
75- * would not emit , so there was no way to know if the menu moved. These new events
74+ * if the same context menu was re-triggered from a new position the callback would
75+ * not trigger , so there was no way to know if the menu moved. These new events
7676 * trigger regardless of current state and mirror the context menu events. This
7777 * means you can now get `onShow`, `onShow`, then `onHide` if you open a context menu,
7878 * move it, then click away.
@@ -89,9 +89,11 @@ export interface MenuProps
8989 onShow ?: ( fromHidden : boolean ) => void ;
9090
9191 /**
92- * Triggers when a hide event is triggered if the menu is currently shown.
92+ * Triggers when a hide event is triggered. This triggers even if the menu
93+ * is already hidden.
94+ * @param fromVisible - True if the menu was previously visible.
9395 */
94- onHide ?: ( ) => void ;
96+ onHide ?: ( fromVisible : boolean ) => void ;
9597}
9698
9799interface MenuState {
@@ -140,7 +142,7 @@ export const Menu = ({
140142 const wasVisible = useRef < boolean > ( false ) ;
141143
142144 // @deprecated -- NOTE: this is to keep backwards compatibility for onVisibilityChange
143- const wasVisibleDepricated = useRef < boolean > ( false ) ;
145+ const wasVisibleDeprecated = useRef < boolean > ( false ) ;
144146 // @deprecated
145147 const visibilityId = useRef < number > ( 0 ) ;
146148
@@ -251,18 +253,19 @@ export const Menu = ({
251253
252254
253255 if ( isFn ( onShow ) ) {
254- onShow ( ! wasVisible . current )
256+ onShow ( ! wasVisible . current ) ;
255257 }
256258
257259 if ( ! wasVisible . current ) {
258- wasVisible . current = true
260+ wasVisible . current = true ;
259261 }
260262
261263 // TODO: remove deprecated functionality
262264 if ( isFn ( onVisibilityChange ) ) {
263265 clearTimeout ( visibilityId . current ) ;
264- if ( ! wasVisibleDepricated . current ) {
266+ if ( ! wasVisibleDeprecated . current ) {
265267 onVisibilityChange ( true ) ;
268+ wasVisibleDeprecated . current = true ;
266269 }
267270 }
268271 }
@@ -286,7 +289,7 @@ export const Menu = ({
286289 } ) ) ;
287290
288291 if ( isFn ( onHide ) ) {
289- onHide ( ) ;
292+ onHide ( wasVisible . current ) ;
290293 }
291294
292295 wasVisible . current = false ;
@@ -295,7 +298,7 @@ export const Menu = ({
295298 if ( isFn ( onVisibilityChange ) ) {
296299 visibilityId . current = setTimeout ( ( ) => {
297300 onVisibilityChange ( false ) ;
298- wasVisibleDepricated . current = false ;
301+ wasVisibleDeprecated . current = false ;
299302 } ) ;
300303 }
301304 }
0 commit comments