-
Notifications
You must be signed in to change notification settings - Fork 234
feat: deprecate sp-menu in PickerBase derived classes #1237
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
Conversation
@Westbrook there's still a few SplitButton failures, and I now see that the markup is a little different for it. I'm wondering if you've thought of any alternatives to the current usage that requires the popover to be created by the client. I'd like to try to simplify that usage as well as part of this change, but there's definitely a conflict between the |
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.
While you're here can you confirm that the slot documentation for each of these element is correct based on this change (not to say it was 100% correct before). For instance, this was wrong before and is more wrong now: https://github.com/adobe/spectrum-web-components/blob/main/packages/split-button/src/SplitButton.ts#L44 Action Menu looks like it has the same twice out of date listing while Picker seems like it just needs to be specifically updated for this change.
super.firstUpdated(changedProperties); | ||
|
||
this.optionsMenu = this.querySelector('sp-menu') as Menu; | ||
this.optionsMenu = this.shadowRoot.querySelector('sp-menu') as Menu; |
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.
With this in the shadow root we should like refactor to:
@query('sp-menu')
private optionsMenu!: Menu;
There's even a caching mechanism in the query
decorator we can activate if we'd like.
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.
oh hey, we can. Nice!
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.
oh hey, we can't quite (this still gets reparented by the popover, so that refactor leads to null results when the menu is open)
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.
Double-check my changes here. Is it okay to have the optionsMenu!
if it gets initialized in firstUpdated
?
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.
In theory @query('sp-menu', true)
would cache this, but if the timing still doesn't work out right, no problem.
We "know" the options menu will be set everywhere it's used, so we can still use the !
in my oppinion.
Also, the SplitButton test failures all originate in how that component manages it's items a little different: https://github.com/adobe/spectrum-web-components/blob/main/packages/split-button/src/SplitButton.ts#L180 |
super.firstUpdated(changedProperties); | ||
|
||
this.optionsMenu = this.querySelector('sp-menu') as Menu; | ||
this.optionsMenu = this.shadowRoot.querySelector('sp-menu') as Menu; |
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.
In theory @query('sp-menu', true)
would cache this, but if the timing still doesn't work out right, no problem.
We "know" the options menu will be set everywhere it's used, so we can still use the !
in my oppinion.
packages/picker/src/Picker.ts
Outdated
if (this.optionsMenu.menuItems.length) { | ||
this.manageSelection(); | ||
if (this.open && this.optionsMenu) { | ||
await this.optionsMenu.updateComplete; |
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.
For reference in this example, with the sp-menu
removed, you'd get this.menuItems === []
and this.optionsMenu.menuItems === [MenuItem, MenuItem, MenuItem, MenuItem]
fdeb60b
to
9d6f4f0
Compare
packages/picker/src/Picker.ts
Outdated
if (!this.open) { | ||
this.menuItems = [ | ||
...this.querySelectorAll(`sp-menu-item`), | ||
] as MenuItem[]; |
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.
My thinking here is that it should be okay to change the menu items, but that it works best when the menu is closed.
f6b235b
to
daac8fe
Compare
It'd be good to update the picker tests so the slotted content tests actually open/select something (and we validate that the slotted content wasn't reparented). It'd also be good to add a test where we add or remove a menu item and ensure that things still work (and the newly added item is selectable). I might need some help with those though, and if this otherwise looks good it might make sense to add an issue and merge. |
I'm seeing some errors in the storybook pages now that I'm digging deeper, so hold on any merge here. |
a2e592b
to
be6b177
Compare
@Westbrook I think I've addressed all the feedback you had (except I can add a separate issue for improving some of the tests here. I know the visual diffs caught some things the tests could have caught earlier (but that also means there's at least a little coverage of some scenarios I noticed the tests were missing). |
There's still work to update all the tests/docs, but if this is working right most tests should pass.
Also properly import sp-menu for usage in PickerBase
I'd do more on the manageSelection changes here, but I think we can remove a lot of this by using new options from #1189
The @query wasn't working here -- ended up with null deference errors. Also need to initialize menuItems in firstUpdated in case the menu state is already open. Also revert an aria-role change that shouldn't have been committed. Bad late-night flawgic.
01b0f1d
to
108d6c6
Compare
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.
LGTM.
Would love to see reparentChildren
leveraged in ActiveOverlay
as a stand along PR before we get to the bigger menu changes you'll be looking at next. The reusability of that API is a really great addition to the library! Thanks for the deep work here.
Description
This is an update to #1198 with the functional approach. It should also address some of the test failures there.
I'll leave as a draft until I update all the related docs/tests.
Related Issue
#1235
Motivation and Context
Simpler APIs are generally better.
How Has This Been Tested?
Just some basic doc page testing so far.
Screenshots (if appropriate):
Types of changes
Checklist: