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

[ModalUnstyled] Fix behavior of not respecting props ariaHidden value #32055

Merged
merged 7 commits into from Jun 8, 2022

Conversation

tech-meppem
Copy link
Contributor

@tech-meppem tech-meppem commented Mar 30, 2022

Fix for Modal ariaHidden prop as stated in issue #32029.

Fixes #32039

It is using props.ariaHidden directly because there was a eslint error putting it in the const {} = props above.

@mui-bot
Copy link

mui-bot commented Mar 30, 2022

Details of bundle changes

Generated by 🚫 dangerJS against a28f6a7

@danilo-leal danilo-leal changed the title fix: ModalUnstyled not respecting props AriaHidden value [ModalUnstyled] Fix behavior of not respecting props ariaHidden value Mar 30, 2022
@danilo-leal danilo-leal added component: modal This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base labels Mar 30, 2022
@tech-meppem
Copy link
Contributor Author

tech-meppem commented Mar 30, 2022

After further investigation, that simple fix is not enough. I am continuing down the rabbit hole of ModalManager.

Fixed in ModalManager too.

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Changes look good, let's add test to ensure it won't break again in the future :)

@mnajdova
Copy link
Member

@tech-meppem could you add tests for the fix?

@mnajdova mnajdova added the PR: needs test The pull request can't be merged label Apr 22, 2022
@tech-meppem
Copy link
Contributor Author

@tech-meppem could you add tests for the fix?

Hi
I am now working on the test, sorry for the delay, I don't have much time to work on them.
But I have encountered the same problem as I did with my other PR's, with the re-rendering issue.

This is the code I added:

  it('forwards the ariaHidden prop', () => {
    const elementRef = React.createRef();
    // by default, aria-hidden == !open
    // so test the inverses of that
    const { setProps } = render(
      <ModalUnstyled
        open
        aria-hidden
        ref={elementRef}
        keepMounted
        data-testid="modal"
      >
        <div />
      </ModalUnstyled>,
    );

    const { current: element } = elementRef;
    expect(element.getAttribute('aria-hidden'), 'true when modal open').to.equal('true');

    setProps({
      open: false,
      "aria-hidden": false,
    });

    const elementPost = screen.getByTestId('modal');
    expect(elementPost.getAttribute('aria-hidden'), 'null when modal closed').to.equal(null);
  });

However, a problem occurs in that when I change the props with setProps, the HTML dom has not been re-rendered before I do the next check.
Would it just be better to do one of these, or split them out into 2 separate tests?

@mnajdova
Copy link
Member

Take a look at the Modal's test for patterns on how to write the tests.

In this specific case, I would just write two different tests, it would even be more readable.

@tech-meppem
Copy link
Contributor Author

tech-meppem commented May 27, 2022

Take a look at the Modal's test for patterns on how to write the tests.

In this specific case, I would just write two different tests, it would even be more readable.

I've updated it now, and have added 4 tests, for all 4 use cases (open/close + set via props/not set via props).

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for spending time on it :)

@ZeeshanTamboli ZeeshanTamboli removed the PR: needs test The pull request can't be merged label Jun 2, 2022
@mnajdova mnajdova merged commit 7a9d971 into mui:master Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: modal This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Modal] Modal has aria-hidden set to true, even if keepMounted is true, and it's partly visible.
5 participants