diff --git a/docs/data/material/components/click-away-listener/click-away-listener.md b/docs/data/material/components/click-away-listener/click-away-listener.md index eeeb0a89e33131..993962209853fa 100644 --- a/docs/data/material/components/click-away-listener/click-away-listener.md +++ b/docs/data/material/components/click-away-listener/click-away-listener.md @@ -9,11 +9,60 @@ githubLabel: 'component: ClickAwayListener'

The Click-Away Listener component detects when a click event happens outside of its child element.

-## This document has moved +{{"component": "@mui/docs/ComponentLinkHeader", "design": false}} -:::warning -Please refer to the [Click-Away Listener](/base-ui/react-click-away-listener/) component page in the MUI Base docs for demos and details on usage. +## Introduction + +Click-Away Listener is a utility component that listens for click events outside of its child. +(Note that it only accepts _one_ child element.) +This is useful for components like the [Popper](/material-ui/react-popper/) which should close when the user clicks anywhere else in the document. +Click-Away Listener also supports the [Portal](/material-ui/react-portal/) component. + +The demo below shows how to hide a menu dropdown when users click anywhere else on the page: + +{{"demo": "ClickAway.js"}} + +## Basics + +### Import + +```jsx +import ClickAwayListener from '@mui/material/ClickAwayListener'; +``` + +## Customization + +### Use with Portal + +The following demo uses the [Portal](/material-ui/react-portal/) component to render the dropdown into a new subtree outside of the current DOM hierarchy: + +{{"demo": "PortalClickAway.js"}} -Click-Away Listener is a part of the standalone MUI Base component library. -It is currently re-exported from `@mui/material` for your convenience, but it will be removed from this package in a future major version after MUI Base gets a stable release. +### Listening for leading events + +By default, the Click-Away Listener component responds to **trailing events**—the _end_ of a click or touch. + +You can set the component to listen for **leading events** (the start of a click or touch) using the `mouseEvent` and `touchEvent` props, as shown in the following demo: + +:::warning +When the component is set to listen for leading events, interactions with the scrollbar are ignored. ::: + +{{"demo": "LeadingClickAway.js"}} + +## Accessibility + +By default, Click-Away Listener adds an `onClick` handler to its child. +This can result in screen readers announcing that the child is clickable, even though this `onClick` handler has no effect on the child itself. + +To prevent this behavior, add `role="presentation"` to the child element: + +```tsx + +
+

non-interactive heading

+
+
+``` + +This is also required to fix a known issue in NVDA when using Firefox that prevents the announcement of alert messages—see [this GitHub issue](https://github.com/mui/material-ui/issues/29080) for details. diff --git a/docs/data/material/components/no-ssr/no-ssr.md b/docs/data/material/components/no-ssr/no-ssr.md index ac2611539ebcd3..0f53163f9c147b 100644 --- a/docs/data/material/components/no-ssr/no-ssr.md +++ b/docs/data/material/components/no-ssr/no-ssr.md @@ -8,11 +8,41 @@ components: NoSsr

The No-SSR component defers the rendering of children components from the server to the client.

-## This document has moved +{{"component": "@mui/docs/ComponentLinkHeader", "design": false}} -:::warning -Please refer to the [No-SSR](/base-ui/react-no-ssr/) component page in the MUI Base docs for demos and details on usage. +## Introduction + +No-SSR is a utility component that prevents its children from being rendered on the server, deferring their rendering to the client instead. +This can be useful in a variety of situations, including: + +- To create an escape hatch for broken dependencies that don't support server-side rendering (SSR) +- To improve the time to first paint by only rendering above the fold +- To reduce the rendering time on the server +- To turn on service degradation when the server load is too heavy +- To improve the Time to Interactive (TTI) by only rendering what's important (using the `defer` prop) + +The demo below illustrates how this component works: + +{{"demo": "SimpleNoSsr.js"}} + +## Basics + +### Import -No-SSR is a part of the standalone MUI Base component library. -It is currently re-exported from `@mui/material` for your convenience, but it will be removed from this package in a future major version after MUI Base gets a stable release. +```jsx +import NoSsr from '@mui/material/NoSsr'; +``` + +## Customization + +### Delay client-side rendering + +You can also use No-SSR to delay the rendering of specific components on the client-side—for example, to let the rest of the application load before an especially complex or data-heavy component. + +The following demo shows how to use the `defer` prop to prioritize rendering the rest of the app outside of what is nested within No-SSR: + +{{"demo": "FrameDeferring.js"}} + +:::warning +When using No-SSR in this way, React applies [two commits](https://react.dev/learn/render-and-commit) instead of one. ::: diff --git a/docs/data/material/components/portal/SimplePortal.js b/docs/data/material/components/portal/SimplePortal.js new file mode 100644 index 00000000000000..2f36c6b139184c --- /dev/null +++ b/docs/data/material/components/portal/SimplePortal.js @@ -0,0 +1,29 @@ +import * as React from 'react'; +import Portal from '@mui/material/Portal'; +import { Box } from '@mui/system'; + +export default function SimplePortal() { + const [show, setShow] = React.useState(false); + const container = React.useRef(null); + + const handleClick = () => { + setShow(!show); + }; + + return ( +
+ + + It looks like I will render here. + {show ? ( + container.current}> + But I actually render here! + + ) : null} + + +
+ ); +} diff --git a/docs/data/material/components/portal/SimplePortal.tsx b/docs/data/material/components/portal/SimplePortal.tsx new file mode 100644 index 00000000000000..f7927816df8f9c --- /dev/null +++ b/docs/data/material/components/portal/SimplePortal.tsx @@ -0,0 +1,29 @@ +import * as React from 'react'; +import Portal from '@mui/material/Portal'; +import { Box } from '@mui/system'; + +export default function SimplePortal() { + const [show, setShow] = React.useState(false); + const container = React.useRef(null); + + const handleClick = () => { + setShow(!show); + }; + + return ( +
+ + + It looks like I will render here. + {show ? ( + container.current!}> + But I actually render here! + + ) : null} + + +
+ ); +} diff --git a/docs/data/material/components/portal/SimplePortal.tsx.preview b/docs/data/material/components/portal/SimplePortal.tsx.preview new file mode 100644 index 00000000000000..8d96c108b1317b --- /dev/null +++ b/docs/data/material/components/portal/SimplePortal.tsx.preview @@ -0,0 +1,12 @@ + + + It looks like I will render here. + {show ? ( + container.current!}> + But I actually render here! + + ) : null} + + \ No newline at end of file diff --git a/docs/data/material/components/portal/portal.md b/docs/data/material/components/portal/portal.md index d8e92c4db26418..8b4cadf5bb0593 100644 --- a/docs/data/material/components/portal/portal.md +++ b/docs/data/material/components/portal/portal.md @@ -9,11 +9,49 @@ githubLabel: 'component: Portal'

The Portal component lets you render its children into a DOM node that exists outside of the Portal's own DOM hierarchy.

-## This document has moved +{{"component": "@mui/docs/ComponentLinkHeader", "design": false}} -:::warning -Please refer to the [Portal](/base-ui/react-portal/) component page in the MUI Base docs for demos and details on usage. +## Introduction -Portal is a part of the standalone MUI Base component library. -It is currently re-exported from `@mui/material` for your convenience, but it will be removed from this package in a future major version after MUI Base gets a stable release. +Portal is a utility component built around [React's `createPortal()` API](https://react.dev/reference/react-dom/createPortal). +It gives you the functionality of `createPortal()` in a convenient component form. +It's used internally by the [Modal](/base-ui/react-modal/) and [Popper](/base-ui/react-popper/) components. + +:::info +According to [the React docs](https://react.dev/reference/react-dom/createPortal), portals are useful when "you need the child element to visually 'break out' of its container"—for instance, modals and tooltips, which need to exist outside of the normal flow of the document. +::: + +Normally, children of a component are rendered within that component's DOM tree. +But sometimes it's necessary to mount a child at a different location in the DOM. +The Portal component accepts a `container` prop that passes a `ref` to the DOM node where its children will be mounted. + +The following demo shows how a `` nested within a Portal can be appended to a node outside of the Portal's DOM hierarchy—click **Mount children** to see how it behaves: + +{{"demo": "SimplePortal.js"}} + +## Basics + +### Import + +```jsx +import Portal from '@mui/material/Portal'; +``` + +## Customization + +### Server-side Portals + +The DOM API isn't available on the server, so you need to use the `container` prop callback. +This callback is called during a React layout effect: + +```jsx + document.getElementById('filter-panel')!}> + + +``` + +:::error +The Portal component cannot be used to render child elements on the server—client-side hydration is necessary. +This is because React doesn't support the [`createPortal()` API](https://react.dev/reference/react-dom/createPortal) on the server. +See [this GitHub issue](https://github.com/facebook/react/issues/13097) for details. ::: diff --git a/docs/data/material/components/textarea-autosize/textarea-autosize.md b/docs/data/material/components/textarea-autosize/textarea-autosize.md index be947db10d8717..36d8075daf913b 100644 --- a/docs/data/material/components/textarea-autosize/textarea-autosize.md +++ b/docs/data/material/components/textarea-autosize/textarea-autosize.md @@ -7,13 +7,35 @@ githubLabel: 'component: TextareaAutosize' # Textarea Autosize -

The Textarea Autosize component gives you a textarea HTML element that automatically adjusts its height to match the length of the content within.

+

The Textarea Autosize component automatically adjusts its height to match the length of the content within.

-## This document has moved +{{"component": "@mui/docs/ComponentLinkHeader", "design": false}} -:::warning -Please refer to the [Textarea Autosize](/base-ui/react-textarea-autosize/) component page in the MUI Base docs for demos and details on usage. +## Introduction -Textarea Autosize is a part of the standalone MUI Base component library. -It is currently re-exported from `@mui/material` for your convenience, but it will be removed from this package in a future major version after MUI Base gets a stable release. -::: +Textarea Autosize is a utility component that replaces the native `