Skip to content

Enable user to configure modal's scrollBehavior#2355

Closed
jmestxr wants to merge 13 commits intoMarkBind:masterfrom
jmestxr:configure-modal-scrollbar-position
Closed

Enable user to configure modal's scrollBehavior#2355
jmestxr wants to merge 13 commits intoMarkBind:masterfrom
jmestxr:configure-modal-scrollbar-position

Conversation

@jmestxr
Copy link
Contributor

@jmestxr jmestxr commented Aug 16, 2023

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • DevOps
  • Improve developer experience
  • Others, please explain:

Closes #2327
Fixes #2322

Overview of changes:
User can now configure scroll position of modal by setting scroll-behavior prop to be 'inside' (default) or 'outside', e.g. <modal scroll-behavior='outside'> ...

The modal CSS styles for the respective scroll-behavior values are set within the opened() method which is called after modal is opened (see @opened event here).

For scroll-behavior = 'outside', basically what I did was:

  1. Set the overflow-y property of the outermost modal container to scroll, which allowed user to mouseclick on scrollbar without causing modal to close unexpectedly. However, it resulted in this:

Screenshot 2023-08-17 at 12 09 28 AM



where the grey area is the part that user can click to close the modal and the white area is the overflow part.



  1. To solve the above issue, I used javascript to query the modal content's total height (including the overflow part) to adjust the height of the grey part to fill up the white area, resulting in this:

Screenshot 2023-08-17 at 12 12 13 AM



  1. Then adjust the background colors of relevant containers to get the following:
Screen.Recording.2023-08-16.at.11.37.44.PM.mov

Anything you'd like to highlight/discuss:

When both scroll-behavior='outside' and center='true' are set, modal does not render properly when content overflows. To fix this, I modified the code such that center='true' only takes effect when scroll-behavior='inside'.

Testing instructions:

  1. cd into packages/cli/test/functional/test_site and run markbind serve -d
  2. navigate to test_site/testModals.html in browser and test out the modals

Proposed commit message: (wrap lines at 72 characters)


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No unrelated changes

Previously, modal is rendered properly when both
scroll-behavior='outside' and center='true' is set.

Remove effect of centering modal when scroll-behavior is set to
'outside'.

center='true' has effect only if scroll-behavior is set to 'inside'
@jmestxr jmestxr marked this pull request as ready for review August 17, 2023 06:27
@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Merging #2355 (79ad9a1) into master (cd5ba3d) will increase coverage by 0.28%.
Report is 2 commits behind head on master.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2355      +/-   ##
==========================================
+ Coverage   44.82%   45.11%   +0.28%     
==========================================
  Files         122      123       +1     
  Lines        5133     5165      +32     
  Branches     1082     1086       +4     
==========================================
+ Hits         2301     2330      +29     
- Misses       2513     2516       +3     
  Partials      319      319              
Files Changed Coverage Δ
packages/vue-components/src/Modal.vue 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@damithc
Copy link
Contributor

damithc commented Aug 22, 2023

@jmestxr is this PR ready for review?

@jmestxr
Copy link
Contributor Author

jmestxr commented Aug 22, 2023

@jmestxr is this PR ready for review?

@damithc hi prof, this PR is ready for review

@damithc
Copy link
Contributor

damithc commented Aug 22, 2023

@MarkBind/active-devs for your review ...

// To adjust modal styles according to scrollBehavior

const modal = $vfm.get(this.id)[0].$el;
const modalContainer = modal.querySelector('.vfm__container');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the properties mentioned here help you in the stuff you are doing below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I can use those to refactor some of the styles to the <style> sheet, together with data() props. But I still need to use javascript to set overflow-y to the outermost container, and query the overflowed content height to adjust the modal container height.

I have just committed those changes

Copy link
Contributor

@tlylt tlylt Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For outermost container, does using <vue-final-modal> class="abc" work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works. Thanks!

@tlylt
Copy link
Contributor

tlylt commented Aug 23, 2023

Wondering whether bootstrap Modal'smodal-dialog-scrollable will be helpful here? https://getbootstrap.com/docs/5.1/components/modal/#scrolling-long-content

@jmestxr jmestxr marked this pull request as draft August 24, 2023 04:07
@jmestxr
Copy link
Contributor Author

jmestxr commented Aug 24, 2023

Wondering whether bootstrap Modal'smodal-dialog-scrollable will be helpful here? https://getbootstrap.com/docs/5.1/components/modal/#scrolling-long-content

Ah, this actually solves a previous PR #2322 in a more straightforward manner

I'll revert the solution from #2322 and use modal-dialog-scrollable instead for scroll-behavior='inside'

@jmestxr jmestxr marked this pull request as ready for review August 24, 2023 11:44
@jmestxr jmestxr marked this pull request as draft August 24, 2023 14:58
@jmestxr jmestxr marked this pull request as ready for review August 24, 2023 14:58
@tlylt
Copy link
Contributor

tlylt commented Aug 26, 2023

@jmestxr
Followed your testing step here:

Testing instructions:
cd into packages/cli/test/functional/test_site and run markbind serve -d
navigate to test_site/testModals.html in browser and test out the modals

When clicking on the outside scrollbar, i'm getting the same old error of auto closing the entire modal. Could you verify/re-check?

Here's the gif:
4JKApwyuNw

In fact I just checked the preview of UG here

Encountering this exact error as well.

@jmestxr
Copy link
Contributor Author

jmestxr commented Aug 27, 2023

@jmestxr Followed your testing step here:

Testing instructions:
cd into packages/cli/test/functional/test_site and run markbind serve -d
navigate to test_site/testModals.html in browser and test out the modals

When clicking on the outside scrollbar, i'm getting the same old error of auto closing the entire modal. Could you verify/re-check?

Here's the gif: 4JKApwyuNw

In fact I just checked the preview of UG here

Encountering this exact error as well.

Apologies! I have just done a fix, notably for the calculation of isContentOverflow. The behavior should be correct now

@tlylt
Copy link
Contributor

tlylt commented Aug 27, 2023

Apologies! I have just done a fix, notably for the calculation of isContentOverflow. The behavior should be correct now

Just tried it, seems very janky?

  • sometimes it just doesn't work, when i click on the scrollbar it closes the entire modal

  • if i resize the window, it behaviors weirdly
    image

@jmestxr
Copy link
Contributor Author

jmestxr commented Aug 27, 2023

Apologies! I have just done a fix, notably for the calculation of isContentOverflow. The behavior should be correct now

Just tried it, seems very janky?

  • sometimes it just doesn't work, when i click on the scrollbar it closes the entire modal
  • if i resize the window, it behaviors weirdly

Okay, perhaps dynamically changing the height isn't the best way to go. Solution will become too unnecessarily complex just for this issue. Either way it doesn't solve the actual problem that the scroll-bar is within the closable area of the modal. Perhaps should instead try migrating vue-final-modal to higher versions which doesn't seem to have this issue: https://vue-final-modal.org/use-cases/modal-long-scroll

I think I'll close this PR and meanwhile open a new issue for solving #2322 using modal-dialog-scrollable?

@tlylt
Copy link
Contributor

tlylt commented Aug 27, 2023

Okay, perhaps dynamically changing the height isn't the best way to go. Solution will become too unnecessarily complex just for this issue. Either way it doesn't solve the actual problem that the scroll-bar is within the closable area of the modal. Perhaps should instead try migrating vue-final-modal to higher versions which doesn't seem to have this issue: vue-final-modal.org/use-cases/modal-long-scroll

Agreed. Good exploration still 👍 I think the solution that I would go with is to either wait till we migrate vue-final-modal, or do a deep dive into the package, and find out what changes did they make to fix this issue in newer versions (might take time and have complicated issues, so I'm not recommending).

I think I'll close this PR and meanwhile open a new issue for solving #2322 using modal-dialog-scrollable?

Sure, if it turns out that using modal-dialog-scrollable can help significantly improve the implementation over the existing one then please go ahead. If not we can keep it as is.

@jmestxr
Copy link
Contributor Author

jmestxr commented Aug 28, 2023

Okay, perhaps dynamically changing the height isn't the best way to go. Solution will become too unnecessarily complex just for this issue. Either way it doesn't solve the actual problem that the scroll-bar is within the closable area of the modal. Perhaps should instead try migrating vue-final-modal to higher versions which doesn't seem to have this issue: vue-final-modal.org/use-cases/modal-long-scroll

Agreed. Good exploration still 👍 I think the solution that I would go with is to either wait till we migrate vue-final-modal, or do a deep dive into the package, and find out what changes did they make to fix this issue in newer versions (might take time and have complicated issues, so I'm not recommending).

I think I'll close this PR and meanwhile open a new issue for solving #2322 using modal-dialog-scrollable?

Sure, if it turns out that using modal-dialog-scrollable can help significantly improve the implementation over the existing one then please go ahead. If not we can keep it as is.

Will do. Thanks for the review @tlylt !

@jmestxr jmestxr closed this Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to configure modal scrollbar position

3 participants