Skip to content

Commit

Permalink
move disableInitialContentFocus prop to Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeshanTamboli committed Oct 26, 2024
1 parent 2033eb8 commit 3b7de07
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/pages/material-ui/api/modal.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"disableAutoFocus": { "type": { "name": "bool" }, "default": "false" },
"disableEnforceFocus": { "type": { "name": "bool" }, "default": "false" },
"disableEscapeKeyDown": { "type": { "name": "bool" }, "default": "false" },
"disableInitialContentFocus": { "type": { "name": "bool" }, "default": "false" },
"disablePortal": { "type": { "name": "bool" }, "default": "false" },
"disableRestoreFocus": { "type": { "name": "bool" }, "default": "false" },
"disableScrollLock": { "type": { "name": "bool" }, "default": "false" },
Expand Down
1 change: 1 addition & 0 deletions docs/pages/material-ui/api/popover.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"children": { "type": { "name": "node" } },
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
"container": { "type": { "name": "union", "description": "HTML element<br>&#124;&nbsp;func" } },
"disableInitialContentFocus": { "type": { "name": "bool" }, "default": "false" },
"disableScrollLock": { "type": { "name": "bool" }, "default": "false" },
"elevation": { "type": { "name": "custom", "description": "integer" }, "default": "8" },
"marginThreshold": { "type": { "name": "number" }, "default": "16" },
Expand Down
3 changes: 3 additions & 0 deletions docs/translations/api-docs/modal/modal.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"disableEscapeKeyDown": {
"description": "If <code>true</code>, hitting escape will not fire the <code>onClose</code> callback."
},
"disableInitialContentFocus": {
"description": "By default the dialog content element is focused when opened.<br>Set the property to <code>true</code> to disable this behavior and focus will be placed on the first focusable element respecting <code>tabIndex</code> order, including elements explicitly marked with <code>tabIndex={-1}</code>."
},
"disablePortal": {
"description": "The <code>children</code> will be under the DOM hierarchy of the parent component."
},
Expand Down
3 changes: 3 additions & 0 deletions docs/translations/api-docs/popover/popover.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"container": {
"description": "An HTML element, component instance, or function that returns either. The <code>container</code> will passed to the Modal component.<br>By default, it uses the body of the anchorEl&#39;s top-level document object, so it&#39;s simply <code>document.body</code> most of the time."
},
"disableInitialContentFocus": {
"description": "By default the dialog content element is focused when opened.<br>Set the property to <code>true</code> to disable this behavior and focus will be placed on the first focusable element respecting <code>tabIndex</code> order, including elements explicitly marked with <code>tabIndex={-1}</code>."
},
"disableScrollLock": { "description": "Disable the scroll lock behavior." },
"elevation": { "description": "The elevation of the popover." },
"marginThreshold": {
Expand Down
10 changes: 0 additions & 10 deletions packages/mui-material/src/Dialog/Dialog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ export interface DialogProps extends StandardProps<ModalProps, 'children'> {
* @default false
*/
disableEscapeKeyDown?: boolean;
/**
* By default the dialog content element is focused when opened.
*
* Set the property to `true` to disable this behavior and focus will be
* placed on the first focusable element respecting `tabIndex` order,
* including elements explicitly marked with `tabIndex={-1}`.
*
* @default false
*/
disableInitialContentFocus?: boolean;
/**
* If `true`, the dialog is full-screen.
* @default false
Expand Down
8 changes: 6 additions & 2 deletions packages/mui-material/src/Drawer/Drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ const Drawer = React.forwardRef(function Drawer(inProps, ref) {
className,
elevation = 16,
hideBackdrop = false,
ModalProps: { BackdropProps: BackdropPropsProp, ...ModalProps } = {},
ModalProps: {
BackdropProps: BackdropPropsProp,
disableInitialContentFocus = false,
...ModalProps
} = {},
onClose,
open = false,
PaperProps = {},
Expand Down Expand Up @@ -239,7 +243,7 @@ const Drawer = React.forwardRef(function Drawer(inProps, ref) {
<DrawerPaper
elevation={variant === 'temporary' ? elevation : 0}
square
tabIndex={ModalProps.disableInitialContentFocus ? undefined : -1}
tabIndex={disableInitialContentFocus ? undefined : -1}
{...PaperProps}
className={clsx(classes.paper, PaperProps.className)}
ownerState={ownerState}
Expand Down
10 changes: 10 additions & 0 deletions packages/mui-material/src/Modal/Modal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ export interface ModalOwnProps {
* @default false
*/
disableEscapeKeyDown?: boolean;
/**
* By default the dialog content element is focused when opened.
*
* Set the property to `true` to disable this behavior and focus will be
* placed on the first focusable element respecting `tabIndex` order,
* including elements explicitly marked with `tabIndex={-1}`.
*
* @default false
*/
disableInitialContentFocus?: boolean;
/**
* The `children` will be under the DOM hierarchy of the parent component.
* @default false
Expand Down
10 changes: 10 additions & 0 deletions packages/mui-material/src/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ Modal.propTypes /* remove-proptypes */ = {
* @default false
*/
disableEscapeKeyDown: PropTypes.bool,
/**
* By default the dialog content element is focused when opened.
*
* Set the property to `true` to disable this behavior and focus will be
* placed on the first focusable element respecting `tabIndex` order,
* including elements explicitly marked with `tabIndex={-1}`.
*
* @default false
*/
disableInitialContentFocus: PropTypes.bool,
/**
* The `children` will be under the DOM hierarchy of the parent component.
* @default false
Expand Down
15 changes: 13 additions & 2 deletions packages/mui-material/src/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
children,
className,
container: containerProp,
disableScrollLock = false,
disableInitialContentFocus = false,
elevation = 8,
marginThreshold = 16,
open,
Expand All @@ -121,7 +123,6 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
TransitionComponent = Grow,
transitionDuration: transitionDurationProp = 'auto',
TransitionProps: { onEntering, ...TransitionProps } = {},
disableScrollLock = false,
...other
} = props;

Expand Down Expand Up @@ -428,7 +429,7 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
>
<PaperSlot
{...paperProps}
tabIndex={other.disableInitialContentFocus ? undefined : -1}
tabIndex={disableInitialContentFocus ? undefined : -1}
ref={handlePaperRef}
>
{children}
Expand Down Expand Up @@ -565,6 +566,16 @@ Popover.propTypes /* remove-proptypes */ = {
HTMLElementType,
PropTypes.func,
]),
/**
* By default the dialog content element is focused when opened.
*
* Set the property to `true` to disable this behavior and focus will be
* placed on the first focusable element respecting `tabIndex` order,
* including elements explicitly marked with `tabIndex={-1}`.
*
* @default false
*/
disableInitialContentFocus: PropTypes.bool,
/**
* Disable the scroll lock behavior.
* @default false
Expand Down

0 comments on commit 3b7de07

Please sign in to comment.