GetJobber / atlantis

🔱 Atlantis
https://atlantis.getjobber.com
MIT License
27 stars 30 forks source link

refactor(components): Replace ToggleOpen with HandleOpen #2083

Closed ZakaryH closed 1 month ago

ZakaryH commented 1 month ago

Motivations

Combobox doesn't allow you to actually interact with the Activator again once the combobox is open. Maybe some day it will, but that day is not today.

With that, the toggleOpen method is a bit misleading. in practice it is a one way toggle that can only ever toggle from closed -> open.

the toggleOpen method has a dead code path that only exists in theory. functionally, you have no way to interact with the activator while the combobox is open. we will close it when you click outside the combobox, when you press ESC, when you interact with an Action that has the default close on click, or when you make a selection in single select mode.

the only way you can interact with it would be through DOM manipulation which is not realistic.

it's similar to how we handle the overlay

        {open && (
          <div
            className={styles.overlay}
            onClick={() => handleClose()}
            data-testid="ATL-Combobox-Overlay"
          />
        )}

this one is more explicit since the condition ensures we'd never even have this element rendered if it was closed, but there conceptually it's the same. we know that in practice, you can't interact with the activator once the combobox is open.

Changes

Added

Changed

the exposed method from the API is now named open

Deprecated

Removed

remvoed some tests that were checking cases that aren't real, or doing interactions no user could do

Fixed

Security

Testing

play around with some normal comboboxes, custom Chip/Button activator comboboxes and finally the fully customized activator combobox.

all of them should still open when the activator is interacted with, and close as expected when clicking outside, pressing ESC, making selections in single select mode etc.

it will even look like it closes when you click the activator while it's open, just know that's the handleClose on the overlay doing it in reality.

Changes can be tested via Pre-release


In Atlantis we use Github's built in pull request reviews.

Random photo of Atlantis