Skip to content

Conversation

adixon-adobe
Copy link
Collaborator

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

  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • [] I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • [] I have added tests to cover my changes.
  • [] All new and existing tests passed.

@adixon-adobe adixon-adobe requested a review from Westbrook March 2, 2021 16:08
@adixon-adobe
Copy link
Collaborator Author

adixon-adobe commented Mar 2, 2021

@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 Button & Picker patterns here.

Copy link
Contributor

@Westbrook Westbrook left a 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;
Copy link
Contributor

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.

Copy link
Collaborator Author

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!

Copy link
Collaborator Author

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)

Copy link
Collaborator Author

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?

Copy link
Contributor

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.

@Westbrook
Copy link
Contributor

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;
Copy link
Contributor

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.

if (this.optionsMenu.menuItems.length) {
this.manageSelection();
if (this.open && this.optionsMenu) {
await this.optionsMenu.updateComplete;
Copy link
Contributor

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]

@adixon-adobe adixon-adobe force-pushed the adixon-1235/sp-menu-deprecate-some-usage branch from fdeb60b to 9d6f4f0 Compare March 4, 2021 03:11
if (!this.open) {
this.menuItems = [
...this.querySelectorAll(`sp-menu-item`),
] as MenuItem[];
Copy link
Collaborator Author

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.

@adixon-adobe adixon-adobe marked this pull request as ready for review March 4, 2021 04:15
@adixon-adobe adixon-adobe force-pushed the adixon-1235/sp-menu-deprecate-some-usage branch from f6b235b to daac8fe Compare March 4, 2021 04:16
@adixon-adobe
Copy link
Collaborator Author

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.

@adixon-adobe
Copy link
Collaborator Author

I'm seeing some errors in the storybook pages now that I'm digging deeper, so hold on any merge here.

@adixon-adobe adixon-adobe force-pushed the adixon-1235/sp-menu-deprecate-some-usage branch from a2e592b to be6b177 Compare March 4, 2021 14:55
@adixon-adobe
Copy link
Collaborator Author

@Westbrook I think I've addressed all the feedback you had (except @query('sp-menu', true) which doesn't work.

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.
@adixon-adobe adixon-adobe force-pushed the adixon-1235/sp-menu-deprecate-some-usage branch from 01b0f1d to 108d6c6 Compare March 9, 2021 17:25
Copy link
Contributor

@Westbrook Westbrook left a 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.

@Westbrook Westbrook merged commit e408d61 into main Mar 9, 2021
@Westbrook Westbrook deleted the adixon-1235/sp-menu-deprecate-some-usage branch March 9, 2021 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants