I have a fixed element with dynamic height (changing when resizing the browser width ) like the example below :
https://stackblitz.com/edit/react-yuqarh?file=demo.tsx
the element working like a menu :
- it should be opened in first load (it work)
- hidden when user press hide (partially work)
- when click on menu icon open (it work)
in hidden mode I used negative bottom value but this value is fixed while the element height changing if the user resize the browser which causes the element to disappear.
this element is actually a search component with some inputs but I simplified
3
Answers
This should work
If you want to move this element ouside the viewport, you can use transform: translateY(100%); instead of bottom: -125px
If we don’t do conditional rendering, which I believe would be the ideal solution (for that case, the other answer would be the way to go), the solution to your issue would require simply to extract your burger menu from the div that disappears, as it follows:
I would even go as far as suggesting you to have a useToggle custom hook that would have the logic of showing/hiding elements, as it’s something fairly common and you most likely will be using it in other components.