@@ -35,6 +35,12 @@ export interface CModalProps extends HTMLAttributes<HTMLDivElement> {
3535 * @ignore
3636 */
3737 duration ?: number
38+ /**
39+ * Puts the focus on the modal when shown.
40+ *
41+ * @since v4.10.0
42+ */
43+ focus ?: boolean
3844 /**
3945 * Set modal to covers the entire user viewport.
4046 */
@@ -96,6 +102,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
96102 backdrop = true ,
97103 className,
98104 duration = 150 ,
105+ focus = true ,
99106 fullscreen,
100107 keyboard = true ,
101108 onClose,
@@ -134,9 +141,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
134141 document . addEventListener ( 'mouseup' , handleClickOutside )
135142 document . addEventListener ( 'keydown' , handleKeyDown )
136143 } else {
137- if ( activeElementRef . current ) {
138- activeElementRef . current . focus ( )
139- }
144+ activeElementRef . current ?. focus ( )
140145 }
141146
142147 return ( ) => {
@@ -172,7 +177,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
172177
173178 setTimeout (
174179 ( ) => {
175- modalRef . current ?. focus ( )
180+ focus && modalRef . current ?. focus ( )
176181 } ,
177182 transition ? duration : 0 ,
178183 )
@@ -271,6 +276,7 @@ CModal.propTypes = {
271276 children : PropTypes . node ,
272277 className : PropTypes . string ,
273278 duration : PropTypes . number ,
279+ focus : PropTypes . bool ,
274280 fullscreen : PropTypes . oneOfType ( [
275281 PropTypes . bool ,
276282 PropTypes . oneOf < 'sm' | 'md' | 'lg' | 'xl' | 'xxl' > ( [ 'sm' , 'md' , 'lg' , 'xl' , 'xxl' ] ) ,
0 commit comments