Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(island-ui): Filter Dialog - Scroll doesn't work on iOS #15896

Merged
merged 5 commits into from
Sep 5, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Sep 4, 2024

Filter Dialog - Scroll doesn't work on iOS

What

See video:
https://www.icloud.com/photos/#/icloudlinks/0a0egsoTs-s2RKhU64XpLjlmw/0/

On mobile devices (at least on iOS) when you open up the filter dialog, you can't scroll down.

Url's where you can test the filter menu:

After fiddling around with this on my iOS I've managed to fix the issue for me by no longer using the reakit/dialog "prevent scroll" functionality and instead writing my own.

Please help me test this feature on different mobile phone browsers 🙏

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced dialog functionality to prevent background scrolling when the dialog is active.
    • Updated dialog behavior to function as a modal, improving user interaction.
  • Bug Fixes
    • Improved clarity in comments for better understanding of functionality.

@RunarVestmann RunarVestmann added the automerge Merge this PR as soon as all checks pass label Sep 4, 2024
@RunarVestmann RunarVestmann requested a review from a team as a code owner September 4, 2024 15:47
Copy link
Contributor

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes to the Filter.tsx component involve the introduction of a usePreventBodyScroll hook to manage the body's scroll behavior when a dialog is open. The useDialogState function now includes a modal: true parameter to ensure modal behavior, and the Dialog component's props have been adjusted to define scroll behavior explicitly. Minor textual corrections in comments were also made to enhance code clarity.

Changes

Files Change Summary
libs/island-ui/core/src/lib/Filter/Filter.tsx Added usePreventBodyScroll hook for managing body scroll; modified useDialogState for modal behavior; adjusted Dialog props; made minor comment corrections.
libs/island-ui/core/src/lib/Filter/usePreventBodyScroll.ts Introduced usePreventBodyScroll hook to manage body's scroll behavior based on a boolean parameter.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@RunarVestmann RunarVestmann removed the automerge Merge this PR as soon as all checks pass label Sep 4, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2af2801 and be1c6bc.

Files selected for processing (1)
  • libs/island-ui/core/src/lib/Filter/Filter.tsx (6 hunks)
Additional context used
Path-based instructions (1)
libs/island-ui/core/src/lib/Filter/Filter.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (4)
libs/island-ui/core/src/lib/Filter/Filter.tsx (4)

1-1: LGTM!

The import statement change is approved as it is necessary for the new usePreventBodyScroll hook.


65-88: LGTM!

The usePreventBodyScroll hook is implemented correctly and adheres to the best practices. The code changes are approved.


106-106: LGTM!

The modal: true parameter is correctly added to the useDialogState function call to align with the new scroll prevention logic. The code change is approved.


115-115: LGTM!

The usePreventBodyScroll hook is correctly invoked based on the dialog's visibility state and the variant prop. The code change is approved.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 4, 2024

Datadog Report

All test runs dfbd717 🔗

34 Total Test Services: 0 Failed, 33 Passed
🔻 Test Sessions change in coverage: 8 decreased, 3 increased, 133 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-web 0 0 0 2 0 7.76s 1 no change Link
api 0 0 0 4 0 2.92s 1 no change Link
application-api-files 0 0 0 12 0 5.64s 1 no change Link
application-core 0 0 0 90 0 18.89s 1 increased (+0.2%) Link
application-system-api 0 0 0 122 2 3m 4.89s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 42.39s 1 no change Link
application-templates-accident-notification 0 0 0 98 0 17.11s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 11.13s 1 no change Link
application-templates-driving-license 0 0 0 13 0 15.59s 1 no change Link
application-templates-example-payment 0 0 0 2 0 11.74s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (8)

This report shows up to 5 code coverage decreases.

  • shared-form-fields - jest 40.09% (-0.26%) - Details
  • island-ui-core - jest 28.75% (-0.21%) - Details
  • shared-components - jest 34.93% (-0.17%) - Details
  • auth-react - jest 32.28% (-0.14%) - Details
  • portals-core - jest 24.81% (-0.08%) - Details

Copy link

codecov bot commented Sep 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.93%. Comparing base (bd2eb08) to head (be8683a).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #15896   +/-   ##
=======================================
  Coverage   36.93%   36.93%           
=======================================
  Files        6682     6682           
  Lines      136504   136503    -1     
  Branches    38769    38769           
=======================================
  Hits        50415    50415           
+ Misses      86089    86088    -1     
Flag Coverage Δ
api 3.39% <ø> (ø)
application-system-api 41.74% <ø> (ø)
application-templates-parental-leave 28.40% <ø> (+0.11%) ⬆️
clients-charge-fjs-v2 27.54% <ø> (ø)
services-auth-personal-representative 48.12% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
libs/island-ui/core/src/lib/Filter/Filter.tsx 8.00% <ø> (+0.30%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd2eb08...be8683a. Read the comment docs.

@RunarVestmann RunarVestmann added the deploy-feature Deploys features to dev label Sep 5, 2024
@RunarVestmann RunarVestmann changed the title fix(island-ui): Filter Dialog - Mobile scroll doesn't work fix(island-ui): Filter Dialog - Mobile scroll doesn't work oni Sep 5, 2024
@RunarVestmann RunarVestmann changed the title fix(island-ui): Filter Dialog - Mobile scroll doesn't work oni fix(island-ui): Filter Dialog - Scroll doesn't work on iOS Sep 5, 2024
Copy link
Contributor

github-actions bot commented Sep 5, 2024

Affected services are: api,application-system-api,financial-aid-api,financial-aid-backend,financial-aid-open-api,services-auth-personal-representative,air-discount-scheme-web,consultation-portal,contentful-apps,financial-aid-web-osk,financial-aid-web-veita,judicial-system-web,skilavottord-web,web,application-system-form,island-ui-storybook,portals-admin,service-portal,system-e2e,
Feature deployment of your services will begin shortly. Your feature will be accessible here:
https://fixisland-ui-filter-mobile-scroll-api-catalogue.dev01.devland.is/api
https://fixisland-ui-filter-mobile-scroll-application-callback-xrd.internal.dev01.devland.is/application-payment
https://fixisland-ui-filter-mobile-scroll-application-callback-xrd.internal.dev01.devland.is/applications
https://fixisland-ui-filter-mobile-scroll-application-payment-callback-xrd.internal.dev01.devland.is/application-payment
https://fixisland-ui-filter-mobile-scroll-application-payment-callback-xrd.internal.dev01.devland.is/applications
https://fixisland-ui-filter-mobile-scroll-beta.dev01.devland.is/
https://fixisland-ui-filter-mobile-scroll-beta.dev01.devland.is/api
https://fixisland-ui-filter-mobile-scroll-beta.dev01.devland.is/app/skilavottord/
https://fixisland-ui-filter-mobile-scroll-beta.dev01.devland.is/minarsidur
https://fixisland-ui-filter-mobile-scroll-beta.dev01.devland.is/samradsgatt
https://fixisland-ui-filter-mobile-scroll-beta.dev01.devland.is/stjornbord
https://fixisland-ui-filter-mobile-scroll-beta.dev01.devland.is/umsoknir
https://fixisland-ui-filter-mobile-scroll-loftbru-cf.dev01.devland.is/
https://fixisland-ui-filter-mobile-scroll-loftbru.dev01.devland.is/
https://fixisland-ui-filter-mobile-scroll-ui.dev01.devland.is/

Deployed services: application-system-api,application-system-form,service-portal,portals-admin,consultation-portal,api,web,skilavottord-web,island-ui-storybook,air-discount-scheme-web,application-system-api-worker.
Excluded services: contentful-apps

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between be1c6bc and 66bcd8f.

Files selected for processing (1)
  • libs/island-ui/core/src/lib/Filter/Filter.tsx (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • libs/island-ui/core/src/lib/Filter/Filter.tsx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (1)
libs/island-ui/core/src/lib/Filter/Filter.tsx (1)

92-92: Add Unit Tests for usePreventBodyScroll Logic

It appears that the conditional logic in the usePreventBodyScroll hook is not currently covered by unit tests. To prevent regressions and ensure the intended behavior, consider adding unit tests that specifically test this logic when dialog.visible is true and variant is 'dialog'.

  • Location to Address: libs/island-ui/core/src/lib/Filter/Filter.tsx
Analysis chain

Validate the conditional logic in usePreventBodyScroll.

The hook usePreventBodyScroll is used conditionally based on dialog.visible and variant === 'dialog'. This is a smart use of the hook to ensure that scroll prevention only occurs when the dialog is actually visible and in the 'dialog' variant. It would be good to ensure that this logic is covered by unit tests to prevent regressions in behavior, especially in a library component.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if unit tests cover the conditional logic for usePreventBodyScroll.

# Test: Search for unit tests related to usePreventBodyScroll. Expect: Tests that cover the conditional logic.
rg --type typescript -A 5 $'usePreventBodyScroll'

Length of output: 83


Script:

#!/bin/bash
# Description: Verify if unit tests cover the conditional logic for usePreventBodyScroll.

# Test: Search for unit tests related to usePreventBodyScroll. Expect: Tests that cover the conditional logic.
rg --type ts -A 5 'usePreventBodyScroll'

Length of output: 1534


Script:

#!/bin/bash
# Description: Search for test files related to the Filter component to check for indirect coverage of usePreventBodyScroll.

# Find test files that might be related to the Filter component.
fd --type f --name '*Filter*.test.*'

# Search for references to the Filter component in test files.
rg --type ts 'Filter' --glob '*Filter*.test.*' -A 5

Length of output: 490


Script:

#!/bin/bash
# Description: Search for test files related to the Filter component to check for indirect coverage of usePreventBodyScroll.

# Correct the fd command to find test files related to the Filter component.
fd 'Filter.*test.*'

# Search for references to the Filter component in test files.
rg 'Filter' -A 5 --glob '**/*Filter*.test.*'

Length of output: 215


Script:

#!/bin/bash
# Description: Perform a broader search for any test files in the repository to check for indirect coverage of usePreventBodyScroll.

# Find all test files in the repository.
fd '.*test.*'

# Search for references to usePreventBodyScroll in all test files.
rg 'usePreventBodyScroll' -A 5 --glob '**/*test.*'

Length of output: 11846

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 66bcd8f and 47ebec9.

Files selected for processing (2)
  • libs/island-ui/core/src/lib/Filter/Filter.tsx (5 hunks)
  • libs/island-ui/core/src/lib/Filter/usePreventBodyScroll.ts (1 hunks)
Additional context used
Path-based instructions (2)
libs/island-ui/core/src/lib/Filter/usePreventBodyScroll.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/island-ui/core/src/lib/Filter/Filter.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
Additional comments not posted (3)
libs/island-ui/core/src/lib/Filter/usePreventBodyScroll.ts (1)

8-34: Good use of useEffect and cleanup function.

The implementation of useEffect to manage the scroll behavior based on the preventBodyScroll flag is correct. The inclusion of preventBodyScroll in the dependency array ensures that the effect is properly re-invoked when the flag changes. The cleanup function is well-designed to restore the body's initial state, which is crucial for preventing side effects on other components or hooks.

Consider adding more comments to explain why the body's position is set to fixed and the implications of this change, as it might not be immediately clear to other developers or future maintainers of the code.

libs/island-ui/core/src/lib/Filter/Filter.tsx (2)

83-83: Review the use of modal: true in useDialogState.

The addition of modal: true to useDialogState is intended to ensure modal behavior, which is crucial for accessibility and correct dialog management. This change appears to be correctly implemented. However, it would be beneficial to add a comment explaining why this change was necessary, especially since it relates to the scrolling issue addressed in this PR.


178-178: Check the explicit setting of preventBodyScroll={false} in Dialog.

Setting preventBodyScroll={false} explicitly in the Dialog component is a clear and intentional choice to manage scroll behavior. This change is well-documented through the code itself, but adding a comment explaining the reason behind this choice (especially in contrast to the previous behavior) would enhance the clarity and maintainability of the code.

@RunarVestmann RunarVestmann added the automerge Merge this PR as soon as all checks pass label Sep 5, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 47ebec9 and 42ec35d.

Files selected for processing (1)
  • libs/island-ui/core/src/lib/Filter/usePreventBodyScroll.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • libs/island-ui/core/src/lib/Filter/usePreventBodyScroll.ts

@kodiakhq kodiakhq bot merged commit a4c7324 into main Sep 5, 2024
200 of 201 checks passed
@kodiakhq kodiakhq bot deleted the fix/island-ui-filter-mobile-scroll branch September 5, 2024 16:54
jonnigs pushed a commit that referenced this pull request Sep 12, 2024
* Fix mobile scroll

* Keep track of scroll position

* Move hook into separate file

* useRef instead of global variable

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass deploy-feature Deploys features to dev
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants