Skip to content

Commit 3e523b2

Browse files
committed
refactor(CModal): enhance focus trap management
1 parent fca88fc commit 3e523b2

File tree

1 file changed

+30
-31
lines changed
  • packages/coreui-react/src/components/modal

1 file changed

+30
-31
lines changed

packages/coreui-react/src/components/modal/CModal.tsx

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
120120
ref
121121
) => {
122122
const modalRef = useRef<HTMLDivElement>(null)
123-
const modalContentRef = useRef<HTMLDivElement>(null)
124123
const forkedRef = useForkedRef(ref, modalRef)
125124

126125
const [_visible, setVisible] = useState(visible)
@@ -213,37 +212,37 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
213212
{(state) => (
214213
<CConditionalPortal container={container} portal={portal}>
215214
<CModalContext.Provider value={contextValues}>
216-
<div
217-
className={classNames(
218-
'modal',
219-
{
220-
'modal-static': staticBackdrop,
221-
fade: transition,
222-
show: state === 'entered',
223-
},
224-
className
225-
)}
226-
tabIndex={-1}
227-
{...(_visible
228-
? { 'aria-modal': true, role: 'dialog' }
229-
: { 'aria-hidden': 'true' })}
230-
style={{
231-
...(state !== 'exited' && { display: 'block' }),
232-
}}
233-
{...rest}
234-
ref={forkedRef}
235-
>
236-
<CModalDialog
237-
alignment={alignment}
238-
fullscreen={fullscreen}
239-
scrollable={scrollable}
240-
size={size}
215+
<CFocusTrap active={focus && state === 'entered'}>
216+
<div
217+
className={classNames(
218+
'modal',
219+
{
220+
'modal-static': staticBackdrop,
221+
fade: transition,
222+
show: state === 'entered',
223+
},
224+
className
225+
)}
226+
tabIndex={-1}
227+
{...(_visible
228+
? { 'aria-modal': true, role: 'dialog' }
229+
: { 'aria-hidden': 'true' })}
230+
style={{
231+
...(state !== 'exited' && { display: 'block' }),
232+
}}
233+
{...rest}
234+
ref={forkedRef}
241235
>
242-
<CFocusTrap active={focus && state === 'entered'} restoreFocus>
243-
<CModalContent ref={modalContentRef}>{children}</CModalContent>
244-
</CFocusTrap>
245-
</CModalDialog>
246-
</div>
236+
<CModalDialog
237+
alignment={alignment}
238+
fullscreen={fullscreen}
239+
scrollable={scrollable}
240+
size={size}
241+
>
242+
<CModalContent>{children}</CModalContent>
243+
</CModalDialog>
244+
</div>
245+
</CFocusTrap>
247246
</CModalContext.Provider>
248247
</CConditionalPortal>
249248
)}

0 commit comments

Comments
 (0)