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(popover): close popover on scroll #3414

Merged
merged 4 commits into from
Jul 6, 2024
Merged

fix(popover): close popover on scroll #3414

merged 4 commits into from
Jul 6, 2024

Conversation

wingkwong
Copy link
Member

@wingkwong wingkwong commented Jul 5, 2024

Closes #3265

📝 Description

following the same approach done by RA team

⛳️ Current behavior (updates)

See the video in original issue

🚀 New behavior

pr3414-demo.webm

💣 Is this a breaking change (Yes/No):

No

📝 Additional Information

Code in demostration

export const Test = () => {
  const categories = [
    {
      target: "Animals",
      items: [
        {name: "Lion", emoji: "🦁"},
        {name: "Tiger", emoji: "🐅"},
        {name: "Elephant", emoji: "🐘"},
        {name: "Kangaroo", emoji: "🦘"},
        {name: "Panda", emoji: "🐼"},
        {name: "Giraffe", emoji: "🦒"},
        {name: "Zebra", emoji: "🦓"},
        {name: "Cheetah", emoji: "🐆"},
      ],
    },
    {
      target: "Birds",
      items: [
        {name: "Eagle", emoji: "🦅"},
        {name: "Parrot", emoji: "🦜"},
        {name: "Penguin", emoji: "🐧"},
        {name: "Ostrich", emoji: "🦢"},
        {name: "Peacock", emoji: "🦚"},
        {name: "Swan", emoji: "🦢"},
        {name: "Falcon", emoji: "🦅"},
        {name: "Flamingo", emoji: "🦩"},
      ],
    },
  ];
  const DEFAULT_CATEGORY = "Animals";

  return (
    <>
      <form className="h-full overflow-auto">
        <div className="flex justify-between h-[1500px]">
          <div className="flex items-center gap-2">
            <div className="flex w-full flex-wrap gap-4 md:flex-nowrap">
              <Select
                aria-label="Category"
                className="w-52"
                defaultSelectedKeys={[DEFAULT_CATEGORY]}
                name="category"
              >
                {categories.map((category, idx, arr) => (
                  <SelectSection
                    key={category.target}
                    showDivider={idx !== arr.length - 1}
                    title={category.target}
                  >
                    {category.items.map((item) => (
                      <SelectItem key={item.name}>{`${item.emoji} ${item.name}`}</SelectItem>
                    ))}
                  </SelectSection>
                ))}
              </Select>
            </div>
          </div>
          <div className="flex items-center">
            <p className="text-sm text-default-500">
              Press{" "}
              <button aria-label="Enter" className="cursor-pointer" type="submit">
                <Kbd keys={["enter"]}>Enter</Kbd>
              </button>{" "}
              to Add Transaction
            </p>
          </div>
        </div>
      </form>
    </>
  );
};

Summary by CodeRabbit

  • New Features

    • Introduced a new scrollable container in the Select component to display categories and items with emojis.
    • Added a new story WithScrollableContainer to demonstrate the scrollable container functionality.
  • Bug Fixes

    • Fixed an issue where the popover did not close on scroll, enhancing user experience during navigation.

Copy link

linear bot commented Jul 5, 2024

Copy link

vercel bot commented Jul 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextui-docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 6, 2024 7:50am
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 6, 2024 7:50am

Copy link

changeset-bot bot commented Jul 5, 2024

🦋 Changeset detected

Latest commit: a1f9298

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@nextui-org/popover Patch
@nextui-org/autocomplete Patch
@nextui-org/date-picker Patch
@nextui-org/dropdown Patch
@nextui-org/select Patch
@nextui-org/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jul 5, 2024

Walkthrough

The latest update introduces changes to the @nextui-org/popover and @nextui-org/select packages. The former includes a patch to fix the issue where the popover would not close on scroll, addressing issue #3265. It also adds a new test case to ensure the fix works correctly. The @nextui-org/select package sees the addition of a new component that allows for a scrollable container of selectable items, enhancing user interaction within storybook scenarios.

Changes

Files Change Summary
.changeset/sweet-flowers-dress.md Added a summary for the fix in @nextui-org/popover to ensure popover closes on scroll.
packages/components/popover/__tests__/popover.test.tsx Introduced a new test case to check if the popover closes when the user scrolls.
packages/components/popover/src/use-aria-popover.ts Modified the onClose parameter in useReactAriaPopover to conditionally assign a function based on the isNonModal flag.
packages/components/select/stories/select.stories.tsx Added ScrollableContainerTemplate component for rendering a scrollable form with selectable categories and items.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SelectComponent
    participant PopoverComponent
    participant Storybook

    User->>SelectComponent: Click to Open Select
    SelectComponent->>PopoverComponent: Open Popover
    Note right of PopoverComponent: Popover opens
    User->>PopoverComponent: Scroll
    PopoverComponent->>SelectComponent: Trigger onClose
    SelectComponent-->>User: Popover Closes

    User->>Storybook: View WithScrollableContainer Story
    Storybook->>User: Renders ScrollableContainerTemplate
    User->>ScrollableContainerTemplate: Interact with components
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Ensure popover closes on scroll (#3265)
Add test to verify popover closes on scroll (#3265)
Enhance Select component with a scrollable container feature
Ensure Select component renders new scrollable template correctly

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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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
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 ec7c417 and e92cf98.

Files selected for processing (3)
  • .changeset/sweet-flowers-dress.md (1 hunks)
  • packages/components/popover/tests/popover.test.tsx (1 hunks)
  • packages/components/popover/src/use-aria-popover.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/components/popover/tests/popover.test.tsx
Additional comments not posted (2)
.changeset/sweet-flowers-dress.md (1)

1-5: Changeset looks good.

The changeset correctly indicates a patch update for the @nextui-org/popover package and summarizes the change made to close the popover on scroll.

packages/components/popover/src/use-aria-popover.ts (1)

105-105: Conditional assignment of onClose looks good.

The conditional assignment of the onClose function based on the isNonModal flag ensures that the popover closes correctly in non-modal scenarios.

However, ensure that this change is consistent with the rest of the codebase and does not introduce any unintended side effects.

Verification successful

Conditional assignment of onClose is consistent with the rest of the codebase.

The optional nature and conditional invocation of onClose in use-popover.ts ensure that the conditional assignment does not introduce any unintended side effects.

  • onClose is optional and conditionally invoked, which aligns with the conditional assignment logic.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `useReactAriaPopover` function to ensure consistency with the new changes.

# Test: Search for the function usage. Expect: No inconsistent usage.
rg --type typescript $'useReactAriaPopover'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the usage of the `useReactAriaPopover` function to ensure consistency with the new changes.

# Test: Search for the function usage. Expect: No inconsistent usage.
rg --type ts 'useReactAriaPopover'

Length of output: 323


Script:

#!/bin/bash
# Description: Verify the usage of the `onClose` function in `use-popover.ts` to ensure consistency with the new changes.

# Test: Search for the usage of `onClose`. Expect: No inconsistent usage.
rg 'onClose' packages/components/popover/src/use-popover.ts

Length of output: 143

@jrgarciadev
Copy link
Member

@wingkwong please add a storybook so I can check this change 🙏🏻

@wingkwong
Copy link
Member Author

@jrgarciadev added

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 e92cf98 and a1f9298.

Files selected for processing (1)
  • packages/components/select/stories/select.stories.tsx (2 hunks)
Additional comments not posted (2)
packages/components/select/stories/select.stories.tsx (2)

630-693: Ensure proper accessibility.

The ScrollableContainerTemplate function creates a scrollable form with categories and items. Ensure that the scrollable container and items are accessible to screen readers and keyboard navigation.


907-913: LGTM! The WithScrollableContainer story is correctly configured.

The WithScrollableContainer export correctly uses the ScrollableContainerTemplate function to render the story.

@jrgarciadev jrgarciadev merged commit 444d320 into canary Jul 6, 2024
8 checks passed
@jrgarciadev jrgarciadev deleted the fix/eng-1018 branch July 6, 2024 08:04
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.

[BUG] - Select component scrolled through page
2 participants