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

[TrapFocus] Move docs to Base and drop the Unstyled prefix #31954

Merged
merged 2 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import TrapFocus from '@mui/material/Unstable_TrapFocus';
import TrapFocus from '@mui/base/TrapFocus';

export default function BasicTrapFocus() {
const [open, setOpen] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import TrapFocus from '@mui/material/Unstable_TrapFocus';
import TrapFocus from '@mui/base/TrapFocus';

export default function BasicTrapFocus() {
const [open, setOpen] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import TrapFocus from '@mui/material/Unstable_TrapFocus';
import TrapFocus from '@mui/base/TrapFocus';

export default function DisableEnforceFocus() {
const [open, setOpen] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import TrapFocus from '@mui/material/Unstable_TrapFocus';
import TrapFocus from '@mui/base/TrapFocus';

export default function DisableEnforceFocus() {
const [open, setOpen] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import TrapFocus from '@mui/material/Unstable_TrapFocus';
import TrapFocus from '@mui/base/TrapFocus';

export default function LazyTrapFocus() {
const [open, setOpen] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import TrapFocus from '@mui/material/Unstable_TrapFocus';
import TrapFocus from '@mui/base/TrapFocus';

export default function LazyTrapFocus() {
const [open, setOpen] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Portal from '@mui/material/Portal';
import TrapFocus from '@mui/material/Unstable_TrapFocus';
import { Box } from '@mui/system';
import Portal from '@mui/base/Portal';
import TrapFocus from '@mui/base/TrapFocus';

export default function PortalTrapFocus() {
const [open, setOpen] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Portal from '@mui/material/Portal';
import TrapFocus from '@mui/material/Unstable_TrapFocus';
import { Box } from '@mui/system';
import Portal from '@mui/base/Portal';
import TrapFocus from '@mui/base/TrapFocus';

export default function PortalTrapFocus() {
const [open, setOpen] = React.useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
product: material-ui
product: base
title: Trap Focus React component
components: Unstable_TrapFocus
components: TrapFocus
githubLabel: 'component: TrapFocus'
packageName: '@mui/base'
---

# Trap Focus
Expand All @@ -16,8 +17,6 @@ When `open={true}` the trap is enabled, and pressing <kbd class="key">Tab</kbd>

{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}

> ⚠️ The component is experimental and unstable.

## Example

{{"demo": "BasicTrapFocus.js"}}
Expand All @@ -29,7 +28,7 @@ When `open={true}` the trap is enabled, and pressing <kbd class="key">Tab</kbd>
As the component does not have any styles, it also comes with the Base package.

```js
import TrapFocus from '@mui/base/Unstable_TrapFocus';
import TrapFocus from '@mui/base/TrapFocus';
```

## Disable enforce focus
Expand All @@ -51,6 +50,6 @@ When auto focus is disabled, as in the demo below, the component only traps the

## Portal

The following demo uses the [`Portal`](/components/portal/) component to render a subset of the trap focus children into a new "subtree" outside of the current DOM hierarchy; so that they no longer form part of the focus loop.
The following demo uses the [`Portal`](/base/react-portal/) component to render a subset of the trap focus children into a new "subtree" outside of the current DOM hierarchy; so that they no longer form part of the focus loop.

{{"demo": "PortalTrapFocus.js"}}
1 change: 1 addition & 0 deletions docs/data/base/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const pages = [
{ pathname: '/base/react-click-away-listener', title: 'Click-away listener' },
{ pathname: '/base/react-modal', title: 'Modal' },
{ pathname: '/base/react-portal', title: 'Portal' },
{ pathname: '/base/react-trap-focus', title: 'Trap focus' },
],
},
],
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/pagesApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ module.exports = [
{ pathname: '/base/api/tabs-unstyled' },
{ pathname: '/base/api/tab-unstyled' },
{ pathname: '/base/api/textarea-autosize' },
{ pathname: '/base/api/unstable-trap-focus' },
{ pathname: '/base/api/trap-focus' },
];
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import * as React from 'react';
import ApiPage from 'docs/src/modules/components/ApiPage';
import mapApiPageTranslations from 'docs/src/modules/utils/mapApiPageTranslations';
import jsonPageContent from './unstable-trap-focus.json';
import jsonPageContent from './trap-focus.json';

export default function Page(props) {
const { descriptions, pageContent } = props;
return <ApiPage descriptions={descriptions} pageContent={pageContent} />;
}

Page.getInitialProps = () => {
const req = require.context(
'docs/translations/api-docs/unstable-trap-focus',
false,
/unstable-trap-focus.*.json$/,
);
const req = require.context('docs/translations/api-docs/trap-focus', false, /trap-focus.*.json$/);
const descriptions = mapApiPageTranslations(req);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"default": "function defaultIsEnabled() {\n return true;\n}"
}
},
"name": "Unstable_TrapFocus",
"name": "TrapFocus",
"styles": { "classes": [], "globalClasses": {}, "name": null },
"spread": false,
"filename": "/packages/mui-base/src/Unstable_TrapFocus/Unstable_TrapFocus.js",
"filename": "/packages/mui-base/src/TrapFocus/TrapFocus.js",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/trap-focus/\">Trap Focus</a></li></ul>",
"demos": "<ul><li><a href=\"/base/components/trap-focus/\">Trap Focus</a></li></ul>",
"cssComponent": false
}
23 changes: 0 additions & 23 deletions docs/pages/base/api/unstable-trap-focus.js

This file was deleted.

21 changes: 0 additions & 21 deletions docs/pages/base/api/unstable-trap-focus.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
demos,
docs,
demoComponents,
} from 'docs/data/material/components/trap-focus/trap-focus.md?@mui/markdown';
} from 'docs/data/base/components/trap-focus/trap-focus.md?@mui/markdown';

export default function Page() {
return <MarkdownDocs demos={demos} docs={docs} demoComponents={demoComponents} />;
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/blog/2021-q3-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Here are the most significant improvements since early July 2021.
- [TrapFocus](/components/trap-focus/#unstyled)

```jsx
import TrapFocus from '@mui/base/Unstable_TrapFocus';
import TrapFocus from '@mui/base/TrapFocus';
```

### MUI X
Expand Down
11 changes: 0 additions & 11 deletions docs/pages/components/trap-focus.js

This file was deleted.

3 changes: 2 additions & 1 deletion docs/scripts/buildApiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ const migratedBaseComponents = [
'ButtonUnstyled',
'ClickAwayListener',
'InputUnstyled',
'MenuUnstyled',
'MenuItemUnstyled',
'MenuUnstyled',
'ModalUnstyled',
'Portal',
'TrapFocus',
];

export const getGenericComponentInfo = (filename: string): ComponentInfo => {
Expand Down
4 changes: 2 additions & 2 deletions docs/src/modules/utils/replaceMarkdownLinks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('replaceMarkdownLinks', () => {
[ButtonUnstyled](/api/button-unstyled)
[TabPanelUnstyled](/api/tab-panel-unstyled)
[TabsListUnstyled](/api/tabs-list-unstyled)
[Unstable_TrapFocus](/api/unstable-trap-focus)
[TrapFocus](/api/trap-focus)
[ClickAwayListener](/api/click-away-listener)
[IconButton](/api/icon-button)
[LoadingButton](/api/loading-button)
Expand All @@ -217,7 +217,7 @@ describe('replaceMarkdownLinks', () => {
[ButtonUnstyled](/base/api/button-unstyled)
[TabPanelUnstyled](/base/api/tab-panel-unstyled)
[TabsListUnstyled](/base/api/tabs-list-unstyled)
[Unstable_TrapFocus](/base/api/unstable-trap-focus)
[TrapFocus](/base/api/trap-focus)
[ClickAwayListener](/base/api/click-away-listener)
[IconButton](/material-ui/api/icon-button)
[LoadingButton](/material-ui/api/loading-button)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/utils/replaceMarkdownLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const replaceAPILinks = (markdown: string) => {
.replace(/\(\/api\/data-grid([^)]*)\)/gm, '(/x/api/data-grid$1)')
.replace(/\(\/api\/([^"/]+-unstyled)([^)]*)\)/gm, '(/base/api/$1$2)')
.replace(
/\(\/api\/(unstable-trap-focus|click-away-listener|no-ssr|portal|textarea-autosize)([^)]*)\)/gm,
/\(\/api\/(trap-focus|click-away-listener|no-ssr|portal|textarea-autosize)([^)]*)\)/gm,
'(/base/api/$1$2)',
)
.replace(
Expand Down
1 change: 0 additions & 1 deletion docs/src/pagesApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ module.exports = [
{ pathname: '/api-docs/tree-item' },
{ pathname: '/api-docs/tree-view' },
{ pathname: '/api-docs/typography' },
{ pathname: '/api-docs/unstable-trap-focus' },
{ pathname: '/api-docs/year-picker' },
{ pathname: '/api-docs/zoom' },
];
2 changes: 1 addition & 1 deletion packages/mui-base/src/ModalUnstyled/ModalUnstyled.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import composeClasses from '../composeClasses';
import isHostComponent from '../utils/isHostComponent';
import Portal from '../Portal';
import ModalManager, { ariaHidden } from './ModalManager';
import TrapFocus from '../Unstable_TrapFocus';
import TrapFocus from '../TrapFocus';
import { getModalUtilityClass } from './modalUnstyledClasses';

const useUtilityClasses = (ownerState) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import * as React from 'react';

export interface TrapFocusProps {
Expand Down Expand Up @@ -57,10 +56,10 @@ export interface TrapFocusProps {
*
* Demos:
*
* - [Trap Focus](https://mui.com/components/trap-focus/)
* - [Trap Focus](https://mui.com/base/components/trap-focus/)
*
* API:
*
* - [Unstable_TrapFocus API](https://mui.com/api/unstable-trap-focus/)
* - [TrapFocus API](https://mui.com/base/api/trap-focus/)
*/
export default function Unstable_TrapFocus(props: TrapFocusProps): JSX.Element;
export default function TrapFocus(props: TrapFocusProps): JSX.Element;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention, consistent-return, jsx-a11y/no-noninteractive-tabindex */
/* eslint-disable consistent-return, jsx-a11y/no-noninteractive-tabindex */
import * as React from 'react';
import PropTypes from 'prop-types';
import {
Expand Down Expand Up @@ -115,7 +115,7 @@ function defaultIsEnabled() {
/**
* Utility component that locks focus inside the component.
*/
function Unstable_TrapFocus(props) {
function TrapFocus(props) {
const {
children,
disableAutoFocus = false,
Expand Down Expand Up @@ -336,7 +336,7 @@ function Unstable_TrapFocus(props) {
);
}

Unstable_TrapFocus.propTypes /* remove-proptypes */ = {
TrapFocus.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the d.ts file and run "yarn proptypes" |
Expand Down Expand Up @@ -393,7 +393,7 @@ Unstable_TrapFocus.propTypes /* remove-proptypes */ = {

if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line
Unstable_TrapFocus['propTypes' + ''] = exactProp(Unstable_TrapFocus.propTypes);
TrapFocus['propTypes' + ''] = exactProp(TrapFocus.propTypes);
}

export default Unstable_TrapFocus;
export default TrapFocus;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { expect } from 'chai';
import { act, createRenderer, screen } from 'test/utils';
import TrapFocus from '@mui/base/Unstable_TrapFocus';
import TrapFocus from '@mui/base/TrapFocus';
import Portal from '@mui/base/Portal';

describe('<TrapFocus />', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/mui-base/src/TrapFocus/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './TrapFocus';
export * from './TrapFocus';
1 change: 1 addition & 0 deletions packages/mui-base/src/TrapFocus/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './TrapFocus';
2 changes: 0 additions & 2 deletions packages/mui-base/src/Unstable_TrapFocus/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/mui-base/src/Unstable_TrapFocus/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/mui-base/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ export * from './TabUnstyled';
export { default as TextareaAutosize } from './TextareaAutosize';
export * from './TextareaAutosize';

export { default as Unstable_TrapFocus } from './Unstable_TrapFocus';
export * from './Unstable_TrapFocus';
export { default as TrapFocus } from './TrapFocus';
export * from './TrapFocus';
2 changes: 1 addition & 1 deletion packages/mui-base/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ export * from './TabUnstyled';

export { default as TextareaAutosize } from './TextareaAutosize';

export { default as Unstable_TrapFocus } from './Unstable_TrapFocus';
export { default as TrapFocus } from './TrapFocus';
4 changes: 2 additions & 2 deletions packages/mui-material/src/Unstable_TrapFocus/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from '@mui/base/Unstable_TrapFocus';
export * from '@mui/base/Unstable_TrapFocus';
export { default } from '@mui/base/TrapFocus';
export * from '@mui/base/TrapFocus';
2 changes: 1 addition & 1 deletion packages/mui-material/src/Unstable_TrapFocus/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from '@mui/base/Unstable_TrapFocus';
export { default } from '@mui/base/TrapFocus';
2 changes: 1 addition & 1 deletion test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you're adding a new test prefer a new component instead of editing existing f

We're using [`playwright`](https://playwright.dev) to replay user actions.
Each test tests only a single fixture.
A fixture can be loaded with `await renderFixture(fixturePath)` e.g. `renderFixture('Unstable_TrapFocus/OpenTrapFocus')`.
A fixture can be loaded with `await renderFixture(fixturePath)` e.g. `renderFixture('TrapFocus/OpenTrapFocus')`.

## Commands

Expand Down
Loading