Skip to content

chore(island-ui): Update reakit to latest version of ariakit #18848

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Apr 23, 2025

Update reakit to latest version of ariakit

Asana

What

This PR updates ariakit (formerly reakit) to it's latest version.

Why

This fixes a bug where if you have multiple menu components (from ariakit) on a single page. If you were to open one, then scroll that open menu out of view and try to open another one, the first one would scroll back into view.

It's also nice when packages are up to date.

Sidenote

This PR adds the ariakit package and uses it it the judicial-system project and in a few places in island-ui. I decided not to update everywhere, due to the complexity that would entail. Rather, I'd like to make other teams responsible for updating their own code an let both packages live in the meantime.

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

  • New Features
    • Updated context menu components to use a new menu library for improved accessibility and consistency.
  • Refactor
    • Simplified the API for context menu components by consolidating multiple props into a single render prop.
    • Updated internal components to use new imports for menu and visually hidden elements.
    • Refactored type declarations for improved code clarity in input components.
  • Chores
    • Added the new menu library dependency to the project.

@oddsson oddsson requested review from a team as code owners April 23, 2025 11:16
@oddsson oddsson requested a review from albinagu April 23, 2025 11:16
Copy link
Contributor

coderabbitai bot commented Apr 23, 2025

Walkthrough

This change refactors several UI components to replace the usage of the reakit library with @ariakit/react, particularly for menu and button components. The ContextMenu component's API is simplified, removing props such as disclosure, menuLabel, offset, and dataTestId, and introducing a new render prop for custom menu button rendering. Related components and tests are updated to use the new API. Additionally, the IconButton and DatePicker components are updated to import from @ariakit/react instead of reakit. The AsideIcons component in the input library is refactored to use a typed functional component. The Ariakit package is added as a dependency.

Changes

File(s) Change Summary
apps/judicial-system/web/src/components/ContextMenu/ContextMenu.tsx Refactored to use @ariakit/react for menu logic, removed disclosure, menuLabel, offset, and dataTestId props, added render prop, centralized click handling, and updated component signature.
apps/judicial-system/web/src/components/ContextMenu/ContextMenu.spec.tsx Updated tests to remove usage of the menuLabel prop in accordance with the new ContextMenu API.
apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.tsx
apps/judicial-system/web/src/components/Table/Table.tsx
apps/judicial-system/web/src/routes/Shared/Cases/Cases.tsx
Updated usage of ContextMenu to remove deprecated props (menuLabel, disclosure, dataTestId, offset) and use the new render prop for menu button rendering.
apps/judicial-system/web/src/components/IconButton/IconButton.tsx Changed import of Button from reakit to @ariakit/react/button and updated the aria-label attribute.
libs/island-ui/core/src/lib/DatePicker/DatePicker.tsx
libs/island-ui/core/src/lib/Input/Input.tsx
Changed import of VisuallyHidden from reakit to @ariakit/react. In Input.tsx, refactored AsideIcons to a typed functional component (FC<AsideProps>).
package.json Added @ariakit/react as a new dependency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MenuButton (ContextMenu.render)
    participant ContextMenu
    participant Menu
    participant MenuItem

    User->>MenuButton: Clicks menu button
    MenuButton->>ContextMenu: setOpen(true)
    ContextMenu->>Menu: Renders menu with items
    User->>MenuItem: Clicks menu item
    MenuItem->>ContextMenu: handleClick
    ContextMenu->>Menu: setOpen(false), setLoading(true)
    alt Menu item has href
        ContextMenu->>Router: Navigate to href
    else Menu item has onClick
        ContextMenu->>MenuItem: Call onClick
    end
    ContextMenu->>Menu: setLoading(false)
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Copy link

nx-cloud bot commented Apr 23, 2025

View your CI Pipeline Execution ↗ for commit 9fc2824.

Command Status Duration Result
nx run-many --projects judicial-system-api,judi... ❌ Failed 4m 3s View ↗
nx run-many --projects application-api-core,app... ✅ Succeeded 13m 30s View ↗
nx run-many --projects application-system-api -... ✅ Succeeded 14m 20s View ↗
nx run-many --target=build --projects=web --par... ✅ Succeeded 10m 17s View ↗
nx run-many --projects portals-admin,portals-ad... ✅ Succeeded 2m 40s View ↗
nx run-many --projects clients-administration-o... ✅ Succeeded 48s View ↗
nx run-many --projects api,api-catalogue-consts... ✅ Succeeded 55s View ↗
nx run-many --projects example-common-actions,e... ✅ Succeeded 41s View ↗
Additional runs (86) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-04-23 12:02:10 UTC

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: 1

🧹 Nitpick comments (4)
apps/judicial-system/web/src/components/IconButton/IconButton.tsx (2)

3-3: Verify sub‑path import of Ariakit Button

Ariakit exposes all primitives through the main entry (@ariakit/react).
While sub‑path exports such as @ariakit/react/button exist in v0.5+, they were absent in several earlier 0.4.x builds. Should your lock‑file ever resolve to an older patch version the build will fail with
“Cannot find module '@ariakit/react/button'”.

If you don’t need the granular entry for tree‑shaking, consider importing from the root to be future‑proof:

-import { Button } from '@ariakit/react/button'
+import { Button } from '@ariakit/react'

36-36: Hard‑coded aria‑label reduces context for screen readers

"Valmynd" (“Menu”) is generic and no longer tells the user what the menu controls (previously: “Opna valmöguleika fyrir mál”).
For better accessibility, expose the label as a prop so callers can specify a descriptive text, falling back to the generic value if omitted.

-interface Props {
+interface Props {
   ...
+  ariaLabel?: string
 }
 ...
-      aria-label="Valmynd"
+      aria-label={ariaLabel ?? 'Valmynd'}

Call‑sites such as ContextMenu can then pass a domain‑specific string when needed.

apps/judicial-system/web/src/routes/Shared/Cases/Cases.tsx (1)

88-91: String literal bypasses i18n pipeline

"Nýtt mál" is now hard‑coded, whereas the surrounding file consistently uses formatMessage(...) for translatable text.
Please move the string to the Cases.strings.ts messages file (or reuse an existing key) to avoid breaking localisation.

apps/judicial-system/web/src/components/ContextMenu/ContextMenu.tsx (1)

114-119: Provide accessible name when a custom render is supplied

When render is passed the inner text is set to null, leaving the button without an accessible name unless the custom element already carries one.
Recommend requiring callers to supply aria-label via props or adding a fallback:

<MenuButton
  render={render ?? <Button icon="add" loading={isLoading} />}
  store={menu}
  ref={ref}
+ aria-label={title}
>
  {render ? null : title}
</MenuButton>

This guarantees screen‑reader users always get a label.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d442b76 and 9fc2824.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (9)
  • apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.tsx (1 hunks)
  • apps/judicial-system/web/src/components/ContextMenu/ContextMenu.spec.tsx (0 hunks)
  • apps/judicial-system/web/src/components/ContextMenu/ContextMenu.tsx (4 hunks)
  • apps/judicial-system/web/src/components/IconButton/IconButton.tsx (2 hunks)
  • apps/judicial-system/web/src/components/Table/Table.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Shared/Cases/Cases.tsx (1 hunks)
  • libs/island-ui/core/src/lib/DatePicker/DatePicker.tsx (1 hunks)
  • libs/island-ui/core/src/lib/Input/Input.tsx (2 hunks)
  • package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/judicial-system/web/src/components/ContextMenu/ContextMenu.spec.tsx
🧰 Additional context used
📓 Path-based instructions (2)
`apps/**/*`: "Confirm that the code adheres to the following: - NextJS best practices, including file structure, API routes, and static generation methods. - Efficient state manage...

apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
  • apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.tsx
  • apps/judicial-system/web/src/components/IconButton/IconButton.tsx
  • apps/judicial-system/web/src/components/Table/Table.tsx
  • apps/judicial-system/web/src/routes/Shared/Cases/Cases.tsx
  • apps/judicial-system/web/src/components/ContextMenu/ContextMenu.tsx
`libs/**/*`: "Confirm that the code adheres to the following: - Reusability of components and hooks across different NextJS apps. - TypeScript usage for defining props and exportin...

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/DatePicker/DatePicker.tsx
  • libs/island-ui/core/src/lib/Input/Input.tsx
🧠 Learnings (1)
apps/judicial-system/web/src/routes/Shared/Cases/Cases.tsx (1)
Learnt from: gudjong
PR: island-is/island.is#16760
File: apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx:112-118
Timestamp: 2024-11-07T16:05:06.610Z
Learning: In `apps/judicial-system/web/src/routes/Prosecutor/components/CasesAwaitingConfirmationTable/CasesAwaitingConfirmationTable.tsx`, `apps/judicial-system/web/src/routes/Court/components/CasesAwaitingAssignmentTable/CasesAwaitingAssignmentTable.tsx`, and one instance in `apps/judicial-system/web/src/routes/Shared/Cases/PrisonCases.tsx`, it's correct to pass only the `type` prop to `ColumnCaseType` without the `decision` and `parentCaseId` props.
🧬 Code Graph Analysis (1)
apps/judicial-system/web/src/routes/Shared/Cases/Cases.tsx (1)
apps/judicial-system/web/src/components/ContextMenu/ContextMenu.tsx (1)
  • ContextMenu (63-155)
🔇 Additional comments (6)
libs/island-ui/core/src/lib/DatePicker/DatePicker.tsx (1)

17-17: Import successfully updated to the ariakit package.

The import for VisuallyHidden has been correctly updated from the legacy reakit package to the newer @ariakit/react package. This aligns with the broader migration effort described in the PR objectives.

package.json (1)

78-78: New dependency added correctly.

The @ariakit/react package has been properly added to the dependencies with a specific version (0.4.17). This supports the migration from reakit to @ariakit/react while allowing both packages to coexist temporarily, as mentioned in the PR objectives.

apps/judicial-system/web/src/components/Table/Table.tsx (1)

335-352: Context menu API updated correctly.

The ContextMenu implementation has been properly updated to use the new API with a render prop instead of the previous disclosure and menuLabel props. This pattern gives more control over the menu button rendering and should fix the scrolling issue mentioned in the PR objectives.

The implementation maintains the same functionality while using the new API:

  1. Uses a motion.div for animations
  2. Properly stops event propagation to prevent row click when clicking the menu button
  3. Renders the same IconButton as the menu trigger
apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.tsx (1)

181-191: Context menu API updated correctly.

The ContextMenu component usage has been properly updated to use the new API with a render prop instead of the previous approach. This is consistent with the pattern used in other components and aligns with the migration to @ariakit/react.

The implementation properly:

  1. Maintains the same IconButton look and feel
  2. Preserves the disabled state for unavailable files
  3. Correctly stops event propagation when clicking the menu button
libs/island-ui/core/src/lib/Input/Input.tsx (2)

2-3: Import style is correct & forward‑compatible

Good switch to the root @ariakit/react export; the package supplies VisuallyHidden directly so no sub‑path is required.
No action needed.


258-303: Typed functional component improves clarity

Changing AsideIcons to FC<AsideProps> and extracting props inside the body increases readability and type safety.
Implementation looks solid.

Comment on lines +93 to +109
const handleClick = (evt: React.MouseEvent, item: ContextMenuItem) => {
evt.stopPropagation()
evt.preventDefault()

setOpen(false)
setIsLoading(true)

if (item.href) {
router.push(item.href)
return
}

if (item.onClick) {
item.onClick()
return
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Loading state never resets when onClick does not navigate

setIsLoading(true) is set, but false is never restored when an item’s onClick handler performs an in‑place action (e.g. opens a modal).
Consider wrapping the action in a try/finally and resetting the flag, or make onClick return a promise you can await.

- setIsLoading(true)
+ setIsLoading(true)
+
+const complete = () => setIsLoading(false)
 
 if (item.href) {
   router.push(item.href)
-  return
+  complete()
+  return
 }
 
 if (item.onClick) {
-  item.onClick()
-  return
+  const maybePromise = item.onClick()
+  if (maybePromise?.finally) {
+    maybePromise.finally(complete)
+  } else {
+    complete()
+  }
+  return
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleClick = (evt: React.MouseEvent, item: ContextMenuItem) => {
evt.stopPropagation()
evt.preventDefault()
setOpen(false)
setIsLoading(true)
if (item.href) {
router.push(item.href)
return
}
if (item.onClick) {
item.onClick()
return
}
}
const handleClick = (evt: React.MouseEvent, item: ContextMenuItem) => {
evt.stopPropagation()
evt.preventDefault()
setOpen(false)
setIsLoading(true)
const complete = () => setIsLoading(false)
if (item.href) {
router.push(item.href)
complete()
return
}
if (item.onClick) {
const maybePromise = item.onClick()
if (maybePromise?.finally) {
maybePromise.finally(complete)
} else {
complete()
}
return
}
}

@datadog-island-is
Copy link

datadog-island-is bot commented Apr 23, 2025

Datadog Report

All test runs 22ffcf6 🔗

10 Total Test Services: 1 Failed, 9 Passed

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Test Service View
judicial-system-web 6 0 0 338 0 3m 55.27s Link
air-discount-scheme-web 0 0 0 2 0 5.71s Link
api 0 0 0 4 0 3.22s Link
application-api-files 0 0 0 2 0 11.98s Link
application-core 0 0 0 97 0 33.32s Link
application-system-api 0 0 0 46 0 14m 15.09s Link
application-template-api-modules 0 0 0 16 0 5m 41.9s Link
application-templates-accident-notification 0 0 0 140 0 22.58s Link
application-templates-criminal-record 0 0 0 2 0 17.29s Link
application-templates-driving-license 0 0 0 13 0 19.56s Link

❌ Failed Tests (6)

This report shows up to 5 failed tests.

  • <AppealCaseFilesOverview /> should display a context menu for all files - apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.spec.tsx - Details

    Expand for error
     NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted
    
  • <AppealCaseFilesOverview /> should have an option to delete file if the file of category PROSECUTOR_APPEAL_CASE_FILE even though the user is a prosecutor - apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.spec.tsx - Details

    Expand for error
     NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted
    
  • <AppealCaseFilesOverview /> should not have an option to delete file if the file is of category APPEAL_RULING - apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.spec.tsx - Details

    Expand for error
     NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted
    
  • <AppealCaseFilesOverview /> should not have an option to delete file if the file of category PROSECUTOR_APPEAL_BRIEF even though the user is a prosecutor - apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.spec.tsx - Details

    Expand for error
     NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted
    
  • <AppealCaseFilesOverview /> should not have an option to delete file if the file of category PROSECUTOR_APPEAL_CASE_FILE even though the user is a defender - apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.spec.tsx - Details

    Expand for error
     NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted
    

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.

1 participant