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

[RA-3888] feat(menu): adds menu component based on mui menu #558

Merged

Conversation

santanasara
Copy link
Contributor

adds new menu component based on the material ui menu

Description

Adiciona componente Menu baseado no componente do Material UI
https://jirasoftware.catho.com.br/browse/RA-3888

Setup

to view the components behavior, run yarn storybook

Review guide

  • Coverage (coverage status should not regress)
    - yarn test:coverage
  • Unit tests (yarn test:components)
  • Regression
    - first start the storybook for regression tests(and keep it open): yarn test:regression:storybook;
    - then run the regression tests: yarn test:regression
  • Code review
  • TypeScript updated

A11y review

  • A11y checks
    • accessible via keyboard?
    • Identifiable through assistive technology (screen-reader chrome extension)?
    • Semantically correct html elements (or if necessary identified by WAI-ARIA)?
    • Is there a deficiency in color contrast?

Browsers review

  • Layout review
    • Edge
    • Firefox
    • Chrome
    • Safari
    • Mobile
  • Ux review validation

adds new menu component based on the material ui menu
Copy link
Contributor

@MarcosViniciusPC MarcosViniciusPC left a comment

Choose a reason for hiding this comment

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

[] Code review
[x] unit
[x] regression
[] Doc

Comment on lines +36 to +37
id="menu"
data-testid="menu"
Copy link
Contributor

Choose a reason for hiding this comment

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

If the objective is to do tests, I believe that these props can be removed. Use screen.getByRole('presentation') in the test to get the menu.

Suggested change
id="menu"
data-testid="menu"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

id="menu"
data-testid="menu"
theme={materialThemeOverride}
aria-labelledby="button"
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like a problem because whoever uses the component doesn't know that it needs to have an element with id="button" for the menu to be accessible, you know? Furthermore, the component is already somewhat accessible. Below is the component structure
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Comment on lines 50 to 54
const onClickFunc = () => {
const { handleClick } = item;
handleClose();
handleClick();
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This function here causes it to be recalculated every time the list is rendered, which may result in performance losses. What do you think about moving it after the props are destructured?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/** If true, the component is shown. */
open: PropTypes.bool,
/** Menu contents, has a content parameter, an id and a handleClick function. */
items: PropTypes.array,
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about defining exactly what data format should be in this array and thus avoiding unwanted surprises? For example, if someone passes an object without the "content" prop, our component will break, as we use "content" in the MenuItem.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is based on the same data format defined in the typescript file here in the component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

anchorEl: mockAnchorEl,
handleClose: mockHandleClose,
});
const menu = queryByTestId('menu');
Copy link
Contributor

Choose a reason for hiding this comment

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

If you followed the suggestion above, getByRole('presentation') should work here and in other cases where getByTestId is used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

<div>
<Button
id="button"
aria-controls={open ? 'menu' : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
aria-controls={open ? 'menu' : undefined}
aria-controls="presentation"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

id="button"
aria-controls={open ? 'menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
aria-expanded={open ? 'true' : undefined}
aria-expanded={open}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 76 to 83
aria-hidden="true"
aria-label="Menu"
role="button"
id="button"
aria-controls={open ? 'menu' : undefined}
aria-haspopup="true"
aria-expanded={open ? 'true' : undefined}
onClick={handleClick}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar situation to that mentioned previously

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

horizontal: 'left' | 'center' | 'right';
};
keepMounted?: boolean;
handleClose?: (event: {}, reason: 'backdropClick' | 'escapeKeyDown') => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
handleClose?: (event: {}, reason: 'backdropClick' | 'escapeKeyDown') => void;
onClose?: (event: {}, reason: 'backdropClick' | 'escapeKeyDown') => void;

onClose seems to make more sense for those who use the component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

export interface MenuItemProps {
id: string | number;
content: React.ReactNode;
handleClick: Function;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
handleClick: Function;
onClick: Function;

onClick seems to make more sense for those who use the component

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking here and I believe that this prop doesn't even make much sense to stay in the items object. What about including it as a prop (onClick: (item) => {}) of the component instead of placing it inside the object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think your suggestion adds a bit more complexity and my implementation with object literals is superior in this case making the code neater for the user to implement

@MarcosViniciusPC MarcosViniciusPC added status:fix status:suggestion and removed status:reviewing Someone is reviewing this PR labels Apr 29, 2024
improves types and component readbility by screen readers
improves test by using role instead of id
@alizeleal alizeleal added status:reviewing Someone is reviewing this PR and removed status:fix labels Apr 30, 2024
Copy link
Contributor

@MarcosViniciusPC MarcosViniciusPC left a comment

Choose a reason for hiding this comment

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

[] Code
[] Unit
[] Regression
[] Doc

<div>
<button
type="button"
aria-labelledby="Menu"
Copy link
Contributor

Choose a reason for hiding this comment

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

When aria-label is defined, aria-labelledby is not necessary as they have the same purpose

Suggested change
aria-labelledby="Menu"

<Button
aria-controls="presentation"
aria-haspopup="true"
aria-expanded={open}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
aria-expanded={open}
aria-expanded={open}
aria-label="Menu"

components/Menu/Menu.jsx Outdated Show resolved Hide resolved
santanasara and others added 2 commits April 30, 2024 19:31
improves aria labels on documentation component
@alizeleal alizeleal requested a review from MarcosViniciusPC May 2, 2024 18:28
Copy link
Contributor

@alizeleal alizeleal left a comment

Choose a reason for hiding this comment

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

I can't navigate the menu options using tab
Is this the expected behavior?

@alizeleal alizeleal added question Further information is requested status:fix and removed status:reviewing Someone is reviewing this PR labels May 2, 2024
@alizeleal
Copy link
Contributor

Also, he regression tests don't contemplate the opened menu options, only the always visible button

@santanasara
Copy link
Contributor Author

I can't navigate the menu options using tab Is this the expected behavior?

Yes, the material ui menu also doesn't navigate through tab https://mui.com/material-ui/react-menu/#basic-menu

@alizeleal
Copy link
Contributor

I can't navigate the menu options using tab Is this the expected behavior?

Yes, the material ui menu also doesn't navigate through tab https://mui.com/material-ui/react-menu/#basic-menu

In the reference, I cna navigate with the arrows up and down, but not in this component.

@santanasara
Copy link
Contributor Author

Also, he regression tests don't contemplate the opened menu options, only the always visible button

I tried running the regressions on the open menu but I kept getting this error when running yarn test:regression. Do you have a suggestion on how to make it work? I'm not familiar with this "loki" library
image

Failed with "Unable to get position of selector "#regression-test > *". Review the `chromeSelector` option and 
       make sure your story doesn't crash." after 4 tries

navigation issues
@santanasara
Copy link
Contributor Author

santanasara commented May 2, 2024

I can't navigate the menu options using tab Is this the expected behavior?

Yes, the material ui menu also doesn't navigate through tab https://mui.com/material-ui/react-menu/#basic-menu

In the reference, I cna navigate with the arrows up and down, but not in this component.

I installed the component on talent-selection (talent-selection_app) and noticed some changes @MarcosViniciusPC suggested broke the arrow navigation and also broke other behaviours (like the opening behaviour). So I reverted some changes back to what they were before and now arrow navigation seems to work again (see video evidence).
Gravação de tela de 02-05-2024 17:35:59.webm

Copy link

sonarqubecloud bot commented May 2, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
16.3% Duplication on New Code

See analysis details on SonarCloud

@MarcosViniciusPC
Copy link
Contributor

new menu component based on the material

Due to the urgency, we will create a technical debt for us here at ACME to improve these tests in the future.

@MarcosViniciusPC
Copy link
Contributor

I can't navigate the menu options using tab Is this the expected behavior?

Yes, the material ui menu also doesn't navigate through tab https://mui.com/material-ui/react-menu/#basic-menu

In the reference, I cna navigate with the arrows up and down, but not in this component.

I installed the component on talent-selection (talent-selection_app) and noticed some changes @MarcosViniciusPC suggested broke the arrow navigation and also broke other behaviours (like the opening behaviour). So I reverted some changes back to what they were before and now arrow navigation seems to work again (see video evidence). Gravação de tela de 02-05-2024 17:35:59.webm

How did you do the tests? I tried to simulate the navigation behavior using the arrow keys here and was unable to navigate between items. @alizeleal , confirm to me later if it worked for you. If not, let me know so I can create a task to correct the navigation.

Copy link
Contributor

@MarcosViniciusPC MarcosViniciusPC left a comment

Choose a reason for hiding this comment

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

[x] Code review
[x] Unit
[] Regression

@santanasara
Copy link
Contributor Author

I can't navigate the menu options using tab Is this the expected behavior?

Yes, the material ui menu also doesn't navigate through tab https://mui.com/material-ui/react-menu/#basic-menu

In the reference, I cna navigate with the arrows up and down, but not in this component.

I installed the component on talent-selection (talent-selection_app) and noticed some changes @MarcosViniciusPC suggested broke the arrow navigation and also broke other behaviours (like the opening behaviour). So I reverted some changes back to what they were before and now arrow navigation seems to work again (see video evidence). Gravação de tela de 02-05-2024 17:35:59.webm

How did you do the tests? I tried to simulate the navigation behavior using the arrow keys here and was unable to navigate between items. @alizeleal , confirm to me later if it worked for you. If not, let me know so I can create a task to correct the navigation.

I generated a build locally and installed it in the talent-selection application and tested there.

@alizeleal
Copy link
Contributor

I can't navigate the menu options using tab Is this the expected behavior?

Yes, the material ui menu also doesn't navigate through tab https://mui.com/material-ui/react-menu/#basic-menu

In the reference, I cna navigate with the arrows up and down, but not in this component.

I installed the component on talent-selection (talent-selection_app) and noticed some changes @MarcosViniciusPC suggested broke the arrow navigation and also broke other behaviours (like the opening behaviour). So I reverted some changes back to what they were before and now arrow navigation seems to work again (see video evidence). Gravação de tela de 02-05-2024 17:35:59.webm

How did you do the tests? I tried to simulate the navigation behavior using the arrow keys here and was unable to navigate between items. @alizeleal , confirm to me later if it worked for you. If not, let me know so I can create a task to correct the navigation.

I generated a build locally and installed it in the talent-selection application and tested there.

It didn't work in the documentation

@alizeleal alizeleal self-requested a review May 3, 2024 18:32
Copy link
Contributor

@alizeleal alizeleal left a comment

Choose a reason for hiding this comment

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

Approved with the technical debt for the keyboard navigation and regressive test

@MarcosViniciusPC MarcosViniciusPC merged commit fc066e9 into catho:master May 3, 2024
3 checks passed
Copy link

github-actions bot commented May 3, 2024

🎉 This PR is included in version 9.26.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

🎉 This PR is included in version 10.0.0-beta.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants