Skip to content
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

Refactor export menu with new headless UI library #1567

Closed
wants to merge 1 commit into from
Closed

Conversation

axelboc
Copy link
Contributor

@axelboc axelboc commented Feb 7, 2024

react-aria-menubutton is no longer maintained. It is still on React 17 and CommonJS, which is causing issues in our Cypress tests and for consumer applications.

In this PR, I'm starting the migration to another headless UI library called Ariakit, which seems like a well-maintained, featureful, Typescript-first library. I've considered and discarded other options:

  • React Aria from Adobe — I'm not a fan of the fact that it renders class names by default;
  • Headless UI from Tailwind — the number of components is quite limited, which might be a hindrance in the future;
  • Reach UI — no longer maintained

I'll continue the migration in separate PRs.

apps/demo/src/styles.css Show resolved Hide resolved
import styles from './Selector/Selector.module.css';

interface Props {
format: string;
url: URL | (() => Promise<URL | Blob>) | undefined;
}

function ExportEntry(props: Props) {
const { format, url } = props;
const ExportEntry = forwardRef<
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Custom render components need to be open for extension (i.e. forward ref and spread extra props).

}

function ExportMenu(props: Props) {
const { entries, isSlice, align = 'center' } = props;

return (
<Wrapper className={styles.wrapper}>
<Button
<MenuProvider placement={PLACEMENTS[align]}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to do this ourselves anymore.

@@ -108,10 +111,12 @@
}

.option:hover,
.option[data-active-item],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.option:hover and .option:focus will probably be removed once I finish refactoring the other menus.

@axelboc axelboc requested review from loichuder and removed request for loichuder February 7, 2024 15:49
@axelboc axelboc marked this pull request as draft February 7, 2024 15:52
@axelboc
Copy link
Contributor Author

axelboc commented Feb 7, 2024

I'll investigate the strange failing tests tomorrow...

@axelboc axelboc force-pushed the ariakit branch 2 times, most recently from e9adba2 to 6367288 Compare March 26, 2024 14:32
@axelboc
Copy link
Contributor Author

axelboc commented Mar 26, 2024

/approve

Copy link
Contributor Author

@axelboc axelboc left a comment

Choose a reason for hiding this comment

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

Upgrading to the latest version of ariakit solved the error I was having in the tests.

Comment on lines +48 to +61
.exportMenu {
display: flex;
flex-direction: column;
min-width: var(--popover-anchor-width);
margin-top: 0.375rem;
padding: 0.25rem 0;
background-color: var(--h5w-selector-menu--bgColor, white);
overflow: hidden scroll;
scrollbar-width: thin;
box-shadow:
rgba(0, 0, 0, 0.1) 0px 0px 0px 1px,
rgba(0, 0, 0, 0.1) 0px 4px 11px;
outline: none;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will probably be shared with the other menus once I've refactored them.

@@ -108,10 +111,12 @@
}

.option:hover,
.option[data-active-item],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.option:hover and .option:focus will probably be removed once I finish refactoring the other menus.

@axelboc axelboc marked this pull request as ready for review March 26, 2024 15:09
@axelboc axelboc requested a review from loichuder March 26, 2024 15:10
@loichuder
Copy link
Member

Upgrading to the latest version of ariakit solved the error I was having in the tests.

Sweet !

@axelboc axelboc marked this pull request as draft April 4, 2024 09:25
@axelboc
Copy link
Contributor Author

axelboc commented Apr 4, 2024

On hold, as I noticed that this PR increases the bundle size by more than 100 kB, which seems highly unreasonable for just a popover menu. I'll investigate.

@axelboc
Copy link
Contributor Author

axelboc commented May 7, 2024

I've tried with React Aria (in branch react-aria) and I get an increase of 185 kB ... still by refactoring only the Export menu.

Mind blowing...

@axelboc
Copy link
Contributor Author

axelboc commented May 16, 2024

Superseded by #1642

@axelboc axelboc closed this May 16, 2024
@axelboc axelboc deleted the ariakit branch May 16, 2024 09:17
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.

None yet

2 participants