fix(radio): modal jumping when clicking radio #231
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See Jira issue with link to codesandbox: https://jira.dhis2.org/browse/DHIS2-9104
When clicking a radio in a modal that is scrollable, the modal will scroll and the content will be outside of the viewport. This is due to how the modal is scrolling the modal-content only, using
display: flex
. I believe the reason for using flex here is to keep the header above the content when scrolling.The Card rendered by the Modal will have a height of something like 2x of the modal-content. So when a Radio is clicked, the page is for some weird reason (see https://stackoverflow.com/questions/24299567/radio-button-causes-browser-to-jump-to-the-top/24323870) scrolled to the position of the clicked Radio in the
Card-div
. As far as I understand this, it's due to theposition: absolute
on the Radios, and the Card being the closest relative-positioned element.This fix makes the label positioned relative, so when a Radio is clicked, it will not scroll to the position. However, this could potentially make absolutely position elements in the modal behave weirdly, so another solution would be to have a simple
display: block
on the Card ( instead of flex) - but that would mean we would scroll the header as well.Maybe the
ModalContent
should haveposition: relative
as well, to play nice with absolutely positioned elements?@Mohammer5 replied that position relative is not ideal. The inputs are already hidden withopacity: 0
, and it looks likevisibility: hidden
works as well. Source for fix in above stackoverflow.