1 ---
2 sidebar_label: "Stacked Focus Modal"
3 ---
4
5 import { Table, TypeList } from "docs-ui"
6
7 export const metadata = {
8 title: `StackedFocusModal - Admin Components`,
9 }
10
11 # {metadata.title}
12
13 <Note>
14
15 This component is available since Medusa [v2.21.0](https://github.com/medusajs/medusa/releases/tag/v2.21.0).
16
17 </Note>
18
19 The `StackedFocusModal` component renders a full-screen modal above a route modal. The Medusa Admin uses it for selections that need a lot of space, such as the table that adds countries to a region.
20
21 ```tsx
22 import {
23 StackedFocusModal,
24 } from "@medusajs/dashboard/components"
25 ```
26
27 ---
28
29 ## Stacked Modals
30
31 Render a `StackedFocusModal` inside a [RouteFocusModal](../route-focus-modal/page.mdx) or a [RouteDrawer](../route-drawer/page.mdx), which both provide the stacked modal context. Unlike route modals, a `StackedFocusModal` is not tied to a route. The user opens it with a trigger, and the parent modal stays mounted underneath.
32
33 Every `StackedFocusModal` requires an `id` prop. The parent modal uses the ID to track which stacked modal is open, so you can render more than one stacked modal in the same form.
34
35 Use a `StackedFocusModal` when the content needs the full screen, such as a data table. For narrower content, use the [StackedDrawer](../stacked-drawer/page.mdx).
36
37 ---
38
39 ## Example
40
41 The following UI route renders a `StackedFocusModal` inside a `RouteFocusModal` to select products:
42
43 ```tsx title="src/admin/routes/brands/[id]/products/page.tsx"
44 import { Button, Heading } from "@medusajs/ui"
45 import {
46 RouteFocusModal,
47 StackedFocusModal,
48 } from "@medusajs/dashboard/components"
49
50 const STACKED_MODAL_ID = "select-products"
51
52 const BrandProducts = () => {
53 return (
54 <RouteFocusModal>
55 <RouteFocusModal.Header />
56 <RouteFocusModal.Body>
57 <StackedFocusModal id={STACKED_MODAL_ID}>
58 <StackedFocusModal.Trigger asChild>
59 <Button variant="secondary" size="small">
60 Add Products
61 </Button>
62 </StackedFocusModal.Trigger>
63 <StackedFocusModal.Content>
64 <StackedFocusModal.Header>
65 <StackedFocusModal.Title asChild>
66 <Heading>Add Products</Heading>
67 </StackedFocusModal.Title>
68 </StackedFocusModal.Header>
69 <StackedFocusModal.Body>
70 <ProductTable />
71 </StackedFocusModal.Body>
72 <StackedFocusModal.Footer>
73 <StackedFocusModal.Close asChild>
74 <Button variant="secondary" size="small">
75 Cancel
76 </Button>
77 </StackedFocusModal.Close>
78 </StackedFocusModal.Footer>
79 </StackedFocusModal.Content>
80 </StackedFocusModal>
81 </RouteFocusModal.Body>
82 </RouteFocusModal>
83 )
84 }
85
86 export default BrandProducts
87 ```
88
89 To close the modal from your own code, such as after the user confirms the selection, use the `useStackedModal` hook. Refer to the [Stacked Drawer](../stacked-drawer/page.mdx#usestackedmodal) documentation for the hook's returned values.
90
91 ---
92
93 ## Props
94
95 <TypeList
96 types={[
97 {
98 name: "id",
99 type: "`string`",
100 optional: false,
101 description:
102 "A unique identifier for the modal. It differentiates stacked modals registered to the same parent modal. This prop is required.",
103 },
104 {
105 name: "onOpenChangeCallback",
106 type: "`(open: boolean) => void`",
107 optional: true,
108 description:
109 "A function to run when the modal opens or closes. For example, reset the selection when the user closes the modal.",
110 },
111 ]}
112 />
113
114 ---
115
116 ## Sub-components
117
118 <Table>
119 <Table.Header>
120 <Table.Row>
121 <Table.HeaderCell>
122 Component
123 </Table.HeaderCell>
124 <Table.HeaderCell>
125 Description
126 </Table.HeaderCell>
127 </Table.Row>
128 </Table.Header>
129 <Table.Body>
130 <Table.Row>
131 <Table.Cell>
132
133 `StackedFocusModal.Trigger`
134
135 </Table.Cell>
136 <Table.Cell>
137
138 Opens the modal when clicked. Pass `asChild` to use your own button.
139
140 </Table.Cell>
141 </Table.Row>
142 <Table.Row>
143 <Table.Cell>
144
145 `StackedFocusModal.Content`
146
147 </Table.Cell>
148 <Table.Cell>
149
150 The modal's content. It renders a transparent overlay so that the parent modal stays visible.
151
152 </Table.Cell>
153 </Table.Row>
154 <Table.Row>
155 <Table.Cell>
156
157 `StackedFocusModal.Header`
158
159 </Table.Cell>
160 <Table.Cell>
161
162 The modal's header. It renders the close button, so render it even when it has no children.
163
164 </Table.Cell>
165 </Table.Row>
166 <Table.Row>
167 <Table.Cell>
168
169 `StackedFocusModal.Title`
170
171 </Table.Cell>
172 <Table.Cell>
173
174 The modal's title. Pass `asChild` to render your own heading element.
175
176 </Table.Cell>
177 </Table.Row>
178 <Table.Row>
179 <Table.Cell>
180
181 `StackedFocusModal.Description`
182
183 </Table.Cell>
184 <Table.Cell>
185
186 An accessible description of the modal's purpose.
187
188 </Table.Cell>
189 </Table.Row>
190 <Table.Row>
191 <Table.Cell>
192
193 `StackedFocusModal.Body`
194
195 </Table.Cell>
196 <Table.Cell>
197
198 The modal's scrollable content area.
199
200 </Table.Cell>
201 </Table.Row>
202 <Table.Row>
203 <Table.Cell>
204
205 `StackedFocusModal.Footer`
206
207 </Table.Cell>
208 <Table.Cell>
209
210 The modal's footer. Place the cancel and confirm buttons in it.
211
212 </Table.Cell>
213 </Table.Row>
214 <Table.Row>
215 <Table.Cell>
216
217 `StackedFocusModal.Close`
218
219 </Table.Cell>
220 <Table.Cell>
221
222 Closes the modal when clicked, keeping the parent modal open. Pass `asChild` to use your own button.
223
224 </Table.Cell>
225 </Table.Row>
226 </Table.Body>
227 </Table>
228
229 ---
230
231 ## useStackedModal
232
233 `StackedFocusModal` shares the `useStackedModal` hook with the [StackedDrawer](../stacked-drawer/page.mdx#usestackedmodal). The hook returns `getIsOpen` and `setIsOpen` to read and change a stacked modal's open state by its ID, and `register` and `unregister` that the components call for you.
234
235 ```tsx title="src/admin/routes/brands/[id]/products/page.tsx"
236 import { Button } from "@medusajs/ui"
237 import { useStackedModal } from "@medusajs/dashboard/components"
238
239 const ProductTable = () => {
240 const { setIsOpen } = useStackedModal()
241
242 const handleSave = () => {
243 setIsOpen("select-products", false)
244 }
245
246 return (
247 <Button size="small" onClick={handleSave}>
248 Save
249 </Button>
250 )
251 }
252 ```