Skip to content

MenuItem: Refactor to TypeScript - #53132

Merged
mirka merged 2 commits into
WordPress:trunkfrom
bangank36:refactor/menu-item-to-typescript
Aug 10, 2023
Merged

mirka merged 2 commits into
WordPress:trunkfrom
bangank36:refactor/menu-item-to-typescript

Conversation

@bangank36

@bangank36 bangank36 commented Jul 29, 2023 •

Copy link
Copy Markdown
Contributor

What?

Refactor MenuItem component to TypeScript

Why?

Part of #35744, as suggested in #36128 (comment)

How?

Testing Instructions

  • Ensure no type error
  • Component should work as expected

Testing Instructions for Keyboard

Screenshots or screencast

@bangank36 bangank36 changed the title Refactor/menu item to typescript MenuItem: Refactor to TypeScript Jul 29, 2023
@bangank36
bangank36 marked this pull request as ready for review July 29, 2023 03:51
@bangank36
bangank36 requested a review from ajitbohra as a code owner July 29, 2023 03:51
@skorasaurus skorasaurus added [Type] Code Quality Issues or PRs that relate to code quality [Package] Components /packages/components labels Jul 31, 2023
@mirka
mirka self-requested a review August 4, 2023 18:23

@mirka mirka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work here, thank you! 🎉

I noticed a couple small things, but this is very close to landing. Aside from that, we'll also need a changelog entry, and we'll need to resolve the merge conflict (looks like a disabled prop was added recently in #52737).

- Convert menu-item.js to tsx

- Update JSDoc
@bangank36
bangank36 force-pushed the refactor/menu-item-to-typescript branch from 0eb4f0c to 87b0620 Compare August 6, 2023 03:28

@mirka mirka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome work here, thank you!

I really enjoyed collaborating with you on these. Looking forward to see you around more 🙌

@mirka
mirka merged commit eb6a8f7 into WordPress:trunk Aug 10, 2023
@github-actions github-actions Bot added this to the Gutenberg 16.5 milestone Aug 10, 2023
@bangank36

Copy link
Copy Markdown
Contributor Author

I really enjoyed collaborating with you on these. Looking forward to see you around more 🙌

Thank you for taking the time to review these commits, I actually created some other PRs while waiting for the updates
#53379
#53172

Next step would be provide the missing stories for the MenuItem component, FYI I updated the list of missing stories? Though I think it would be wiser to wait for the update on your notes #36128 (comment)

@noahtallen

Copy link
Copy Markdown
Member

Hi @bangank36! We use MenuItem in a couple of places, and I noticed it no longer accepts a couple of Button props:

  • variant
  • isPressed

Are these supposed to be accepted?

@mirka

mirka commented Aug 31, 2023

Copy link
Copy Markdown
Member

@noahtallen We basically omitted a bunch of Button props we thought were inappropriate in a MenuItem context. Can you point to some use cases for variant/isPressed that you think are legitimate? We're open to reconsider.

@noahtallen

Copy link
Copy Markdown
Member

Good question! This is older code, so I'm not sure exactly how much these props are needed, but here is an example:

https://github.com/Automattic/wp-calypso/blob/5956bfa5df72839c5e29cae607f5c0b152d77147/packages/design-picker/src/components/design-picker-category-filter/index.tsx#L69-L86

Here is where it is rendered:

image

@noahtallen

Copy link
Copy Markdown
Member

Though it does look like the design is changing slightly after the update:

image

@mirka

mirka commented Sep 1, 2023

Copy link
Copy Markdown
Member

Yeah, given that the styles are also heavily overridden in that case, it's not a prop that MenuItem will want to officially allow, at least in its current form.

If there's a need for a specific state/style variant, we can add that to MenuItem in a way that's appropriately styled and named. Otherwise, I think for now you should ts-expect-error and TODO on the Calypso side. (We actually did that in one place, too.)

@bangank36

Copy link
Copy Markdown
Contributor Author

given that the styles are also heavily overridden in that case

So do you think MenuItem isSelected is more appropriate in this case @mirka, I also noticed that there is no classname for MenuItem selected state yet

@mirka

mirka commented Sep 1, 2023 •

Copy link
Copy Markdown
Member

So do you think MenuItem isSelected is more appropriate in this case

We'd have to look into it, but off the top of my head, no. Because I don't think the ARIA Menu pattern has a semantic "selected" state. You'd either use a menuitemradio or menuitemcheckbox and set the state on that.

(Also FYI a DropdownMenu v2 is in the works)

@noahtallen

Copy link
Copy Markdown
Member

Otherwise, I think for now you should ts-expect-error and TODO on the Calypso side

Got it -- I did add a couple of one-off wrapper types inline, but I can remove those. Should I just delete the variant/isPressed props if they don't actually do anything?

@mirka

mirka commented Sep 4, 2023

Copy link
Copy Markdown
Member

Got it -- I did add a couple of one-off wrapper types inline, but I can remove those. Should I just delete the variant/isPressed props if they don't actually do anything?

They will do something, because those props are still passed through to the underlying Button. It's just that we "discouraged" it at the TypeScript level.

@noahtallen

noahtallen commented Sep 5, 2023 •

Copy link
Copy Markdown
Member

Good to know! Thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants