+
Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Conversation

clintcs
Copy link
Collaborator

@clintcs clintcs commented Jan 7, 2025

🚀 Description

Drawer currently fires a "close" event on close. Apparently there's now a "toggle" event too—which Chrome recently added support for. So Drawer needs a "toggle" event. But then why would it need a "close" event too? Just for the sake of following native?

I also learned that Popover API elements have showPopover(), hidePopover(), and togglePopover() methods similar to Drawer's show() and close(). If Drawer has a show() method, then should Popover have showPopover(), hidePopover(), and togglePopover()? Or should neither component have those methods because they both have an open attribute?

I ran all of this by @ynotdraw. After some back and forth, we agreed it makes sense to simplify and diverge from native. We do try to follow native, but not slavishly so. Core tends to diverge when it simplifies things for the consumer or cleans things up a lot for us.

So here's what I propose:

  • We replace Drawer's "close" event with "toggle". "toggle" is more useful given it also fires on open, and dispatching two events when one will suffice will only confuse consumers.
  • We remove Drawer's show() and close() methods. Rather than offer two ways to open and close Drawer, consumers can use open—which covers the functionality of both methods and is easier to use in templates.

If everything looks good, I'll bring these changes to Modal next—removing Modal's showModal() and close() methods and its "close" event, and adding a "toggle" event and an open attribute.

For consistency, I'll also add a "toggle" event to other components that have an open attribute. I know of at least one case where a consumer has a need for "toggle" event on Dropdown.

📋 Checklist

🔬 How to Test

  1. Navigate to Drawer in Storybook.
  2. Verify the open attribute opens and closes Drawer.
  3. Verify the "toggle" event in the Actions tab.
  4. Verify that Storybook's controls table looks good.

📸 Images/Videos of Functionality

N/A

Copy link

changeset-bot bot commented Jan 7, 2025

🦋 Changeset detected

Latest commit: d70f5e9

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

This PR includes changesets to release 1 package
Name Type
@crowdstrike/glide-core Minor

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

@clintcs clintcs force-pushed the rework-drawer branch 2 times, most recently from 12888d7 to 80905cb Compare January 7, 2025 16:25
Copy link
Contributor

github-actions bot commented Jan 7, 2025

);
});

it('does not add an `aria-label` when `label` is unset', async () => {
Copy link
Collaborator Author

@clintcs clintcs Jan 7, 2025

Choose a reason for hiding this comment

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

Removed and cleaned up a bunch of tests while I was updating some of them.

We've been gradually removing tests like this that merely test that some property is passed down to into the markup. They don't give us much additional confidence, and our test suites would blow in size if were we to consistently test this kind thing.

* @cssprop [--width] - The width the drawer.
*
* @event close
* @event toggle
Copy link
Collaborator Author

@clintcs clintcs Jan 7, 2025

Choose a reason for hiding this comment

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

Another inconsistency I noticed is how we document events. Take a look at Toggle. Now check out Accordion.

The @event tag as specified by JSDoc would simply be @event toggle—as it is here. What should we do? I personally favor @event toggle given the event is fully documented in Storybook.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was hoping eventually we may be able to populate Storybook with some of these JSDoc comments using some existing tools out there; however, I'm not sure if/when we will. I'd be in favor of this approach for now until we figure out if the JSDoc -> storybook doc generation is something we want to do 👍

})();
}
}
if (this.#isOpen && hasChanged) {
Copy link
Collaborator Author

@clintcs clintcs Jan 7, 2025

Choose a reason for hiding this comment

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

No change other than the addition of hasChanged and I got rid of the IIFE in favor of thening off of this.#openAnimation?.finished—no reason to indent the entire block for a couple lines, I figured.


GlideCoreDrawer.shadowRootOptions.mode = 'open';

it('opens when animated', async () => {
Copy link
Collaborator Author

@clintcs clintcs Jan 7, 2025

Choose a reason for hiding this comment

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

Moved these tests from drawer.test.basics.ts. Also moved the tests in drawer.test.methods.ts here.


GlideCoreDrawer.shadowRootOptions.mode = 'open';

it('focuses itself on open', async () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved this test from drawer.test.closing.ts.


GlideCoreDrawer.shadowRootOptions.mode = 'open';

it('dispatches a "close" event when the "Escape" key is pressed', async () => {
Copy link
Collaborator Author

@clintcs clintcs Jan 7, 2025

Choose a reason for hiding this comment

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

No need to test if "close" (now "toggle") is dispatched on Escape given the open setter handles dispatching the event. We only need to test:

  1. That the event is dispatched when open is set (below).
  2. That open is set when Escape is pressed (in drawer.test.interactions.ts).

@clintcs clintcs force-pushed the rework-drawer branch 4 times, most recently from bd4059d to 3d4d3ed Compare January 7, 2025 19:37

component.open = true;

const aside = component.shadowRoot?.querySelector('[data-test="component"]');
Copy link
Collaborator Author

@clintcs clintcs Jan 7, 2025

Choose a reason for hiding this comment

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

Ugh. These [data-test="component"] and .component patterns are pretty awkward in tests, where we almost always have a const component.

@clintcs clintcs marked this pull request as ready for review January 7, 2025 19:47
@clintcs clintcs mentioned this pull request Jan 7, 2025
* @cssprop [--width] - The width the drawer.
*
* @event close
* @event toggle
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was hoping eventually we may be able to populate Storybook with some of these JSDoc comments using some existing tools out there; however, I'm not sure if/when we will. I'd be in favor of this approach for now until we figure out if the JSDoc -> storybook doc generation is something we want to do 👍

@clintcs
Copy link
Collaborator Author

clintcs commented Jan 7, 2025

I was hoping eventually we may be able to populate Storybook with some of these JSDoc comments using some existing tools out there

Me too. I know there's a schema for doing so. Not sure how well supported it is in Storybook and elsewhere or if it'll be worth the work. But hopefully it's something we'll eventually have time to look into.

@clintcs
Copy link
Collaborator Author

clintcs commented Jan 7, 2025

Pushed a commit with a couple tweaks.

@clintcs clintcs merged commit c0e6911 into main Jan 9, 2025
7 checks passed
@clintcs clintcs deleted the rework-drawer branch January 9, 2025 00:17
@github-actions github-actions bot mentioned this pull request Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载