feat: replace native theme select with floating dropdown UI#32148
Open
owaiss0 wants to merge 11 commits into
Open
feat: replace native theme select with floating dropdown UI#32148owaiss0 wants to merge 11 commits into
owaiss0 wants to merge 11 commits into
Conversation
Replace the browser-native <select> element for theme switching with a custom floating dropdown that matches the existing Cloudflare header dropdown pattern (HeaderDropdowns.tsx). Changes: - New ThemeDropdown.tsx React component using @floating-ui/react - New ThemeSelect.astro override wrapping ThemeDropdown - Registered ThemeSelect override in astro.config.ts - Removed obsolete starlight-theme-select CSS overrides from Header.astro The dropdown uses the exact same Starlight SVG icons (sun, moon, laptop, down-caret) with identical sizing and absolute positioning to match the original layout pixel-for-pixel. Includes flip() middleware for mobile footer positioning and scroll-to-close for sidebar compatibility.
Contributor
Review✅ No issues found in commit Code ReviewThis code review is in beta and may not always be helpful — use your judgment. No code review issues found. ConventionsNo convention issues found. Style Guide ReviewNo style-guide issues found. CommandsOnly codeowners can run commands. Post a comment with the command to trigger it.
|
…, context, accessibility, and validation
…and stop menu event propagation
…lected toggling for listbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: Implement Cloudflare-styled Floating Theme Dropdown
📝 Summary
Replaced the browser-native
<select>element for theme switching with a custom floating popover dropdown that matches the existing Cloudflare header dropdown pattern (same design as the "Help" dropdown inHeaderDropdowns.tsx).This implementation is built as a pure Astro & vanilla JS Custom Element (
starlight-theme-select) insideThemeSelect.astro. It executes a tiny inline script immediately as the HTML parses to readlocalStorageand apply the correct active icon and text before the browser paints the screen, providing a 0ms flicker-free (FOUC-free) load experience.🔍 Before vs After
1. Desktop Theme Selector
<select>dropdown.PiCaretDownBoldcaret matching the size and weight of other header dropdowns.2. Mobile Theme Selector
flip()positioning to open upward in the footer, and automatically closes on page scroll.🛠️ Technical Details
aria-haspopup="listbox",aria-expandedstate tracking, and option buttons haverole="option"witharia-selectedtracking for screen reader support.localStorageread and write operations are wrapped intry/catchblock guards to ensure the UI does not crash in Safari Private Mode or other restricted environments.astro.config.tsundercomponents.ThemeSelect, automatically styling the theme selector in both the desktop header and the mobile menu footer.