-
Notifications
You must be signed in to change notification settings - Fork 7
Rework Drawer #587
Rework Drawer #587
Conversation
🦋 Changeset detectedLatest commit: d70f5e9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
12888d7
to
80905cb
Compare
); | ||
}); | ||
|
||
it('does not add an `aria-label` when `label` is unset', async () => { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 then
ing 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 () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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:
- That the event is dispatched when
open
is set (below). - That
open
is set when Escape is pressed (indrawer.test.interactions.ts
).
bd4059d
to
3d4d3ed
Compare
|
||
component.open = true; | ||
|
||
const aside = component.shadowRoot?.querySelector('[data-test="component"]'); |
There was a problem hiding this comment.
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
.
* @cssprop [--width] - The width the drawer. | ||
* | ||
* @event close | ||
* @event toggle |
There was a problem hiding this comment.
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 👍
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. |
Pushed a commit with a couple tweaks. |
🚀 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()
, andtogglePopover()
methods similar to Drawer'sshow()
andclose()
. If Drawer has ashow()
method, then should Popover haveshowPopover()
,hidePopover()
, andtogglePopover()
? Or should neither component have those methods because they both have anopen
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:
"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.show()
andclose()
methods. Rather than offer two ways to open and close Drawer, consumers can useopen
—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()
andclose()
methods and its"close"
event, and adding a"toggle"
event and anopen
attribute.For consistency, I'll also add a
"toggle"
event to other components that have anopen
attribute. I know of at least one case where a consumer has a need for"toggle"
event on Dropdown.📋 Checklist
🔬 How to Test
open
attribute opens and closes Drawer."toggle"
event in the Actions tab.📸 Images/Videos of Functionality
N/A