Spaces:
Sleeping
Sleeping
Pull Request Number: 4233 | |
Title: fix(docs): prevent scrolling up on pressing theme change switch | |
Base Branch: canary | |
Head Branch: macci001/eng-1647 | |
Author: macci001 | |
URL: https://github.com/nextui-org/nextui/pull/4233 | |
State: MERGED | |
Created At: 2024-12-06T13:02:24Z | |
Merged At: 2024-12-06T13:14:04Z | |
Participants: macci001, jrgarciadev | |
Description: | |
Closes # ENG-1647 | |
π Description | |
Prevent scrolling up on pressing theme change switch | |
β³οΈ Current behavior (updates) | |
Pressing the theme change switch scrolls the page up. | |
π New behavior | |
Screen.Recording.2024-12-06.at.6.30.19.PM.mov | |
π£ Is this a breaking change (Yes/No): No | |
Summary by CodeRabbit | |
New Features | |
Enhanced theme switching functionality with improved event handling for mouse and keyboard interactions. | |
Users can now switch themes using the "Enter" and "Space" keys for better accessibility. | |
Bug Fixes | |
Resolved unintended side effects during theme changes by implementing event prevention methods. | |
Commits: | |
- fix(docs): prevent scrolling up on pressing theme change switch\n | |
Labels: | |
Comments: | |
- linear: <p><a href="https://linear.app/nextui-inc/issue/ENG-1647/theme-switch-is-scrolling-the-page-up">ENG-1647 Theme switch is scrolling the page up</a></p>\n- vercel: [vc]: #dQoNW/L6uWr4+cUqigz34WJMu9kw6vY794HnL1DhM+M=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJuZXh0dWktZG9jcy12MiIsInJvb3REaXJlY3RvcnkiOiJhcHBzL2RvY3MiLCJsaXZlRmVlZGJhY2siOnsicmVzb2x2ZWQiOjAsInVucmVzb2x2ZWQiOjAsInRvdGFsIjowLCJsaW5rIjoibmV4dHVpLWRvY3MtdjItZ2l0LW1hY2NpMDAxLWVuZy0xNjQ3LW5leHR1aS1vcmcudmVyY2VsLmFwcCJ9LCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vbmV4dHVpLW9yZy9uZXh0dWktZG9jcy12Mi8yZGh5eFB1aEZ1ZTk5Z0xzYVJ6QVhhOWdkVFhMIiwicHJldmlld1VybCI6Im5leHR1aS1kb2NzLXYyLWdpdC1tYWNjaTAwMS1lbmctMTY0Ny1uZXh0dWktb3JnLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQifSx7Im5hbWUiOiJuZXh0dWktc3Rvcnlib29rLXYyIiwicm9vdERpcmVjdG9yeSI6InBhY2thZ2VzL3N0b3J5Ym9vayIsImluc3BlY3RvclVybCI6Imh0dHBzOi8vdmVyY2VsLmNvbS9uZXh0dWktb3JnL25leHR1aS1zdG9yeWJvb2stdjIvSjg2QzZCQWNUeG9MTENxeUVzVG1uTVFIbzFWbSIsInByZXZpZXdVcmwiOiJuZXh0dWktc3Rvcnlib29rLXYyLWdpdC1tYWNjaTAwMS1lbmctMTY0Ny1uZXh0dWktb3JnLnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQiLCJsaXZlRmVlZGJhY2siOnsicmVzb2x2ZWQiOjAsInVucmVzb2x2ZWQiOjAsInRvdGFsIjowLCJsaW5rIjoibmV4dHVpLXN0b3J5Ym9vay12Mi1naXQtbWFjY2kwMDEtZW5nLTE2NDctbmV4dHVpLW9yZy52ZXJjZWwuYXBwIn19XX0= | |
**The latest updates on your projects**. Learn more about [Vercel for Git βοΈ](https://vercel.link/github-learn-more) | |
| Name | Status | Preview | Comments | Updated (UTC) | | |
| :--- | :----- | :------ | :------- | :------ | | |
| **nextui-docs-v2** | β Ready ([Inspect](https://vercel.com/nextui-org/nextui-docs-v2/2dhyxPuhFue99gLsaRzAXa9gdTXL)) | [Visit Preview](https://nextui-docs-v2-git-macci001-eng-1647-nextui-org.vercel.app) | π¬ [**Add feedback**](https://vercel.live/open-feedback/nextui-docs-v2-git-macci001-eng-1647-nextui-org.vercel.app?via=pr-comment-feedback-link) | Dec 6, 2024 1:04pm | | |
| **nextui-storybook-v2** | β Ready ([Inspect](https://vercel.com/nextui-org/nextui-storybook-v2/J86C6BAcTxoLLCqyEsTmnMQHo1Vm)) | [Visit Preview](https://nextui-storybook-v2-git-macci001-eng-1647-nextui-org.vercel.app) | π¬ [**Add feedback**](https://vercel.live/open-feedback/nextui-storybook-v2-git-macci001-eng-1647-nextui-org.vercel.app?via=pr-comment-feedback-link) | Dec 6, 2024 1:04pm | | |
\n- changeset-bot: ### β οΈ No Changeset found | |
Latest commit: 40c44c6653eacfd0e975d9bf55f73551ca82b849 | |
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.** | |
<details><summary>This PR includes no changesets</summary> | |
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types | |
</details> | |
[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md). | |
[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/nextui-org/nextui/new/macci001/eng-1647?filename=.changeset/smooth-insects-battle.md&value=---%0A%22%40nextui-org%2Fdocs%22%3A%20patch%0A---%0A%0Afix(docs)%3A%20prevent%20scrolling%20up%20on%20pressing%20theme%20change%20switch%0A) | |
\n- coderabbitai: <!-- This is an auto-generated comment: summarize by coderabbit.ai --> | |
<!-- walkthrough_start --> | |
## Walkthrough | |
The changes in this pull request primarily involve modifications to the `ThemeSwitch` component located in `apps/docs/components/theme-switch.tsx`. The `onChange` function has been renamed to `handleThemeChange`, which now accepts a broader range of event types. The function's logic has been refined to calculate the new theme based on the current state, and it includes event handling improvements. Additionally, the component's event handlers have been updated to enhance user interaction through keyboard and mouse events. | |
## Changes | |
| File Path | Change Summary | | |
|---------------------------------------------|-----------------------------------------------------------------------------------------------------| | |
| apps/docs/components/theme-switch.tsx | - Renamed `onChange` to `handleThemeChange` with updated signature. | | |
| | - Added `preventDefault()` and `stopPropagation()` to the event handling. | | |
| | - Encapsulated theme calculation logic within `handleThemeChange`. | | |
| | - Updated `posthog.capture` to use the newly calculated theme. | | |
| | - Modified `useSwitch` hook to use `handleThemeChange`. | | |
| | - Added `onClick` and `onKeyDown` handlers for improved user interaction. | | |
## Possibly related PRs | |
- **#3491**: Addresses slow color changes in sortable table headers during theme transitions. | |
- **#3552**: Resolves a double-click issue on checkbox, toggle, and radio components. | |
- **#3663**: Fixes color discrepancies in the select component. | |
- **#3764**: Improves the styling of ghost danger buttons. | |
- **#3768**: Addresses the `fullWidth` functionality in input and select components. | |
- **#3869**: Fixes label placement in select and input components. | |
## Suggested labels | |
`π Status: In Review` | |
## Suggested reviewers | |
- jrgarciadev | |
- wingkwong | |
<!-- walkthrough_end --> | |
<!-- internal state start --> | |
<!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACIAM0QADwAKekImZABKHn4yGSxw5CYqQj9ELBJoXF5BHDzkZAqq/HgyDmZ4bHJoZAB3TSZ4WOg+jFRkXCFWTTpGBQi26uRqaFYMJiZEAAZtgEZMLEZ0RBVCxESYhdavLGchVYAWACYAZletaABJcIx6ekCjVkhzQjVCATIPloMSIiy8Nw6Q26XniuCwEkQhCwGB8mkUA1aFTh0AAcmQkvgAKpfaDxGgcPqEKgAawANL1eOILogmDifIobtUjrJEIF5mQulJMQJCPFibwMD1iqVypVqrU+m0cIKEV4kZUvP1BvBQXxASt6FoPEsVMrELxJFi0EcedDUK1aIt0LxfP5AiEwswfIQVqgUJMvABREkAcQgewAbI8AOyfTzMXBUQKFaAPSXS9njaBYQhzdmA3z4MPapYKpUlMq4tU1dVOip0GgYp0Ek06tqIroG3oEoZp2ulXghmL68ioXSsCKENbKC4CpByCUYKVMxdm/KceWKlGlBfKxvNdWjLXEo34IamjaSKTQy3Wrw+vwQgPIcIVJg+XBbUwaApUmHEIQaThaExHBZWJSg+lzTdtyod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ftWEuAVj2L6PyKxNjNEwkMc6H8fd1pyi5oECQ+TAgCOzFsNUgoPHZmoe0Mgtkab/E0JnPw8hvKex9sY5W/A0HUBMs6GW2SyAK2NMrCJhAKLoHSfxLJOTBTyL0UcAx7TS7+0/gZGCpCkhWW4vk3kP5r5RRCfJSyE4KHQg3oQt+H9dY43wIfCEsScA+PaTmFJDwVGiy5pcRgsI/wAV4cFL2WBvZcWZPM/RqwqGYE8ppZhrDUBbPDmQSOeyTGFiOMBTZWIp7yHAXFLAiLtmrABWQFRfxSK7mgVsYyjzvGKwvFKQJzJp6z3nk8/W0AUjIE5FscWfI1xeFiJGQo1ARhILiA4BUckRi8vkNkWyAB5IWfIBmyD1MY1Am9sByWJHvXpeJ87Eg5caVYCxECsFGVKNUtDkn6IvIqy+8UqgxQEKLQIzoOyPmkF4aZAgOLUEQBQbetkLBWBprAn6MEpaChUP+Vw2CsCoDghxJk+0dw+iEFxVRkRo3IGMDAGuucImMGttiWJYbeAZIYDwaWLBs3hCGevAAvMKrI0Ae0dwAN7QC0OO6AABfZW6tI6zLvErFWescyACTCYuHbAp31xYY/Fg7hVkAAPw8HxYvSu1c64Nybi3P57cu49z7hIAeQ8yCnrvePR9ZL+VUAXhXAdQ7oCjvHZ8adkzZaGPnUMZWbzODk0psAJaoAVqqIqXgT6O0frTjYG3QGGBgbOBZufJQ101AaBhg9eGiGoAHRmPgAA+qcZAtHAhSgcQwWjfFnJwwRk9aAjxthMEeI8JgCYEwAFZXgPviPQbYZAACcyZRP0Fk0IeIonRPxGTK8NTexeQAA5nhCF048WTXHEYwD+poej9BGPMejX0Nja0uNAA=== --> | |
<!-- internal state end --> | |
<!-- tips_start --> | |
--- | |
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? | |
<details> | |
<summary>β€οΈ Share</summary> | |
- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) | |
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) | |
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) | |
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) | |
</details> | |
<details> | |
<summary>πͺ§ Tips</summary> | |
### Chat | |
There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): | |
- 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 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. | |
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. | |
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. | |
</details> | |
<!-- tips_end -->\n | |
Files Changed: | |
- apps/docs/components/theme-switch.tsx (modified, 23 changes)\n Patch: @@ -1,6 +1,6 @@ | |
"use client"; | |
-import {FC} from "react"; | |
+import {FC, ChangeEvent} from "react"; | |
import {VisuallyHidden} from "@react-aria/visually-hidden"; | |
import {SwitchProps, useSwitch} from "@nextui-org/react"; | |
import {useTheme} from "next-themes"; | |
@@ -22,20 +22,27 @@ export const ThemeSwitch: FC<ThemeSwitchProps> = ({className, classNames}) => { | |
const initialTheme = isSSR ? "light" : theme; | |
- const onChange = () => { | |
- theme === "light" ? setTheme("dark") : setTheme("light"); | |
+ const handleThemeChange = ( | |
+ e?: ChangeEvent<HTMLInputElement> | React.MouseEvent | React.KeyboardEvent, | |
+ ) => { | |
+ e?.preventDefault(); | |
+ e?.stopPropagation(); | |
+ | |
+ const newTheme = theme === "light" ? "dark" : "light"; | |
+ | |
+ setTheme(newTheme); | |
posthog.capture("ThemeChange", { | |
action: "click", | |
category: "theme", | |
- data: theme === "light" ? "dark" : "light", | |
+ data: newTheme, | |
}); | |
}; | |
const {Component, slots, isSelected, getBaseProps, getInputProps, getWrapperProps} = useSwitch({ | |
isSelected: initialTheme === "light", | |
"aria-label": `Switch to ${initialTheme === "light" ? "dark" : "light"} mode`, | |
- onChange, | |
+ onChange: handleThemeChange as (event: ChangeEvent<HTMLInputElement>) => void, | |
}); | |
return ( | |
@@ -46,6 +53,12 @@ export const ThemeSwitch: FC<ThemeSwitchProps> = ({className, classNames}) => { | |
className, | |
classNames?.base, | |
), | |
+ onClick: handleThemeChange, | |
+ onKeyDown: (e: React.KeyboardEvent) => { | |
+ if (e.key === "Enter" || e.key === " ") { | |
+ handleThemeChange(e); | |
+ } | |
+ }, | |
})} | |
> | |
<VisuallyHidden>\n |