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

Replace hand-rolled dropdown on the dashboard and menu-related UI fixes #5037

Merged

Conversation

apata
Copy link
Contributor

@apata apata commented Jan 30, 2025

Changes

  • Removes handrolled dropdowns and replaces them with headlessui Popovers: https://headlessui.com/v1/react/popover

    • Also tried to use headlessui Menu component for datepicker, but unfortunately those were too opinionated to work well with our keybinds.

    • Had to refactor the datepicker: visually that means extremely minor changes (first group doesn't have top padding)

  • Fixes the issue with calendars positioning off screen, aligning their right edge to right of dropdown or right of visible page on smaller screens.

    • Removes flatpickr position styles from CSS and applies position styles with TW.
  • Fixes issues with Dashboard modals not receiving focus

  • Fixes issues with Escape clearing filters instead of closing opened menu / popover

    • This was a bit hacky due to headlessui API: we have to stop Escape propagating from Popover.Button (which receives focus on escaping from Popover). If the button isn't blurred immediately, as this PR does, user would have to tab off the button for the clear all filters keybind to work.
  • Fixes issues with multiple dropdowns being openable at the same time

  • Optimises top bar components re-rendering too many times for no reason

Tests

  • Automated tests have been added

Changelog

  • Entry has been added to changelog
  • This PR does not make a user-facing change

Documentation

  • This change does not need a documentation update

Dark mode

  • The UI has been tested both in dark and light mode

@apata apata changed the base branch from master to saved-segments/singular-bar January 30, 2025 17:06
@apata apata added the preview label Jan 30, 2025
Copy link

Preview environment👷🏼‍♀️🏗️
PR-5037

@apata apata changed the title Saved segments/replace handrolled dropdown Replace hand-rolled dropdown on the dashboard and menu-related UI fixes Jan 30, 2025
Copy link
Contributor

@ukutaht ukutaht left a comment

Choose a reason for hiding this comment

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

Looks good. I had some comments about further improvements that could be made but this PR already does a lot. Not suggesting any of this needs to be part of this PR.

If the button isn't blurred immediately, as this PR does, user would have to tab off the button for the clear all filters keybind to work.

Yeah. OTOH it breaks the expected behaviour that I can:

  1. Open dropdown
  2. Close via escape key
  3. Open again via enter

I think the ideal behaviour would be that stopPropagation only runs when the popover is open. The event would be allowed to propagate if popover is closed without blurring the button. In that case both escape and enter would work as expected after closing the dropdown. I tried using the open render prop to achieve this but the sequence of events didn't allow me to achieve it (the open prop is already false when the key event handler runs).

Not a blocker for sure, it's a tiny detail.

@@ -1,28 +1,6 @@
/* @format */
/* stylelint-disable media-feature-range-notation */
/* stylelint-disable selector-class-pattern */
.flatpickr-calendar::before,
Copy link
Contributor

Choose a reason for hiding this comment

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

👏

: 'md:left-auto md:w-56'
)}
>
<Popover.Panel
Copy link
Contributor

@ukutaht ukutaht Feb 4, 2025

Choose a reason for hiding this comment

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

Nit: The fact that dropdownState changes immediately when the menu is closed sort of negates the close transition. The menu disappears immediately and only the shadow is transitioned away which looks weird if you really pay attention.

Ideally the dropdownState would change to closed after the transition is finished. Or maybe it would be easier to make the different states their own separate Popover.Panel components but I don't know how that would affect the Menu -> Calendar transition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well spotted! I thought it was barely noticeable and was just happy to have finally gotten the following transitions working at all with keyboard and clicks.

  • Closed -> Menu
  • Menu -> Closed
  • Menu -> Calendar
  • Calendar -> Closed
  • Closed -> Calendar

Will look into it once more: I actually didn't try swapping out the panel as you suggest OR driving Transition and Panel directly with the state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it works great as is, just a very minor nitpick. Don't spend too much time polishing it :)

@@ -147,8 +151,12 @@ export function IntervalPicker({ onIntervalUpdate }) {
enterTo="opacity-100 scale-100"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use the same consolidated transition props here as the popovers to make sure they're consistent?

@apata apata merged commit 3eeff88 into saved-segments/singular-bar Feb 4, 2025
8 checks passed
apata added a commit that referenced this pull request Feb 5, 2025
…es (#5037)

* Try popover

* Pass targetRef instead of target, stop Escape clearing filters

* Stop Escape clearing filters when popover menus active

* Attempt get rid of hand-rolled dropdown

* Fix issue with comparison calendar

* Almost works

* Unify styles

* Focus modals on mount

* Refactor date picker logic

* Replace navigate keybinds with straightforward keybinds

* Remove extraneous Calendar component, better props

* Attempt optimise menu re-renders

* Memoise QueryPeriodsMenu, refactor getDatePeriodGroups

* Refactor ComparisonMenu to Popover

* Refactor QueryPeriodMenu to Popover

* Pull calendar out of components

* Refactor calendar to receive position from JS

* Simpler calendar API

* Add click outside listener for Calendar, fix FiltersBar measurements

* Give back top bar room

* Update tests

* Apply unified button text style

* Close calendar on keyboard nav to othe menus as well

* Kinda works

* Works even better

* Working well

* Sometimes menu stays active

* WIP

* Adapter

* Works with error

* Fixed the error

* Remove handrolled isOpen

* Introduce shared adapter

* Share adapter
github-merge-queue bot pushed a commit that referenced this pull request Feb 6, 2025
* Remove the second line for filters

* Remove extraneous class and prevent wrap

* Fix jumpyness

* Replace hand-rolled dropdown on the dashboard and menu-related UI fixes (#5037)

* Try popover

* Pass targetRef instead of target, stop Escape clearing filters

* Stop Escape clearing filters when popover menus active

* Attempt get rid of hand-rolled dropdown

* Fix issue with comparison calendar

* Almost works

* Unify styles

* Focus modals on mount

* Refactor date picker logic

* Replace navigate keybinds with straightforward keybinds

* Remove extraneous Calendar component, better props

* Attempt optimise menu re-renders

* Memoise QueryPeriodsMenu, refactor getDatePeriodGroups

* Refactor ComparisonMenu to Popover

* Refactor QueryPeriodMenu to Popover

* Pull calendar out of components

* Refactor calendar to receive position from JS

* Simpler calendar API

* Add click outside listener for Calendar, fix FiltersBar measurements

* Give back top bar room

* Update tests

* Apply unified button text style

* Close calendar on keyboard nav to othe menus as well

* Kinda works

* Works even better

* Working well

* Sometimes menu stays active

* WIP

* Adapter

* Works with error

* Fixed the error

* Remove handrolled isOpen

* Introduce shared adapter

* Share adapter

* Allow dropshadows in a slightly better way, add more comments

* Share transition with interval picker menu

* Calendar transitions independently

* Calendars are in separate popovers

* Hide outline on supposedly hidden buttons

* Fix arrow appearing on Safari

* Fix difference between calendar dropdown and menu dropdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants