Skip to content

Commit

Permalink
Merge pull request #1435 from habx/fix/4.1/APP-15727
Browse files Browse the repository at this point in the history
APP-15727: fix deps
  • Loading branch information
habx-auto-merge[bot] authored Nov 6, 2020
2 parents 6d3240c + 32f598e commit 94a10e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Menu/Menu.context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'

export const MenuContext = React.createContext<{ close: () => void }>({
export const MenuContext = React.createContext({
close: () => {},
})
17 changes: 12 additions & 5 deletions src/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { breakpoints } from '../breakpoints'
import { TogglePanel, TogglePanelProps } from '../TogglePanel'
import { withTriggerElement } from '../withTriggerElement'

import { MenuContext } from './Menu.context'
import { MenuInstance, InnerMenuProps } from './Menu.interface'
import { FloatingMenu, FullScreenMenu } from './Menu.style'

Expand Down Expand Up @@ -37,13 +38,19 @@ export const InnerMenu = React.forwardRef<HTMLDivElement, InnerMenuProps>(
(modal: Modal<HTMLDivElement>) => {
const content = isFunction(children) ? children(modal) : children

return fullScreenOnMobile && size.width < breakpoints.raw.phone ? (
<FullScreenMenu>{content}</FullScreenMenu>
) : (
<FloatingMenu data-scrollable={scrollable}>{content}</FloatingMenu>
return (
<MenuContext.Provider value={{ close: onClose }}>
{fullScreenOnMobile && size.width < breakpoints.raw.phone ? (
<FullScreenMenu>{content}</FullScreenMenu>
) : (
<FloatingMenu data-scrollable={scrollable}>
{content}
</FloatingMenu>
)}
</MenuContext.Provider>
)
},
[children]
[children, fullScreenOnMobile, scrollable, size.width]
)

const setStyle = React.useCallback<Required<TogglePanelProps>['setStyle']>(
Expand Down
10 changes: 8 additions & 2 deletions src/TogglePanel/TogglePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,21 @@ const InnerTogglePanel = React.forwardRef<
}

setCustomStyle({ ...setStyle(dimensions, triggerDimensions), ...style })
}, [modal.ref, style, triggerRef])
}, [modal.ref, setStyle, style, triggerRef])

React.useEffect(() => {
if (open) {
onOpen?.()
updateStyle()
}
}, [open, updateStyle])

React.useEffect(() => {
if (open) {
onOpen?.()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open])

const size = useWindowSize()

React.useEffect(updateStyle, [children, size]) // eslint-disable-line react-hooks/exhaustive-deps
Expand Down

0 comments on commit 94a10e9

Please sign in to comment.