From 73868fbaf810b48d79dede8f911124f0237f4278 Mon Sep 17 00:00:00 2001 From: Rebecca Alpert Date: Tue, 14 Oct 2025 13:31:08 -0400 Subject: [PATCH 1/3] chore(docs): Update ModalWithDropdown example Example was using out-of-date PatternFly syntax from a prior version. It should now show how to properly add a dropdown to a modal that allows for keyboard accessibility. --- .../src/components/Modal/examples/Modal.md | 10 ++--- .../Modal/examples/ModalWithDropdown.tsx | 37 +++++++++++++++---- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/packages/react-core/src/components/Modal/examples/Modal.md b/packages/react-core/src/components/Modal/examples/Modal.md index 9577b2ede69..e2ab63c122a 100644 --- a/packages/react-core/src/components/Modal/examples/Modal.md +++ b/packages/react-core/src/components/Modal/examples/Modal.md @@ -17,7 +17,7 @@ import formStyles from '@patternfly/react-styles/css/components/Form/form'; ### Basic modals -Basic modals give users the option to either confirm or cancel an action. +Basic modals give users the option to either confirm or cancel an action. To flag an open modal, use the `isOpen` property. To execute a callback when a modal is closed, use the `onClose` property. @@ -71,7 +71,7 @@ To choose a specific width for a modal, use the `width` property. The following ### Custom header -To add a custom header to a modal, your custom content must be passed as a child of the `` component. Do not pass the `title` property to `` when using a custom header. +To add a custom header to a modal, your custom content must be passed as a child of the `` component. Do not pass the `title` property to `` when using a custom header. ```ts file="./ModalCustomHeader.tsx" @@ -113,9 +113,9 @@ To guide users through a series of steps in a modal, you can add a [wizard](/com ### With dropdown -To present a menu of actions or links to a user, you can add a [dropdown](/components/menus/dropdown) to a modal. +To present a menu of actions or links to a user, you can add a [dropdown](/components/menus/dropdown) to a modal. -To allow the dropdown to visually break out of the modal container, set the `menuAppendTo` property to “parent”. Handle the modal’s closing behavior by listening to the `onEscapePress` callback on the `` component. This allows the "escape" key to collapse the dropdown without closing the entire modal. +To allow the dropdown to visually break out of the modal container, set the `popperProps appendTo` property to one of the parent content items in the modal. Otherwise you can use `inline` to allow it to scroll within the modal itself. Using the Dropdown's default append location will interfere with keyboard accessibility due to the modal's built-in focus trap. Handle the modal’s closing behavior by listening to the `onEscapePress` callback on the `` component. This allows the "escape" key to collapse the dropdown without closing the entire modal. ```ts file="./ModalWithDropdown.tsx" @@ -141,7 +141,7 @@ To enable form submission from a button in the modal's footer (outside of the `< ### Custom focus -To customize which element inside the modal receives focus when initially opened, use the `elementToFocus` property`. +To customize which element inside the modal receives focus when initially opened, use the `elementToFocus` property`. ```ts file="./ModalCustomFocus.tsx" diff --git a/packages/react-core/src/components/Modal/examples/ModalWithDropdown.tsx b/packages/react-core/src/components/Modal/examples/ModalWithDropdown.tsx index 1e2104dbb69..91b1a3d2de8 100644 --- a/packages/react-core/src/components/Modal/examples/ModalWithDropdown.tsx +++ b/packages/react-core/src/components/Modal/examples/ModalWithDropdown.tsx @@ -32,8 +32,10 @@ export const ModalWithDropdown: React.FunctionComponent = () => { }; const onFocus = () => { - const element = document.getElementById('modal-dropdown-toggle'); - (element as HTMLElement).focus(); + if (typeof document !== 'undefined') { + const element = document.getElementById('modal-dropdown-toggle'); + (element as HTMLElement)?.focus(); + } }; const onEscapePress = (event: KeyboardEvent) => { @@ -45,6 +47,16 @@ export const ModalWithDropdown: React.FunctionComponent = () => { } }; + const getAppendLocation = () => { + // document doesn't exist when PatternFly website docs framework gets pre-rendered + // this is just to avoid that issue - works fine at runtime without it + if (typeof document !== 'undefined' && document.getElementById) { + return document.getElementById('modal-box-body-with-dropdown'); + } else { + return 'inline'; + } + }; + return (