Skip to content

Commit 078030b

Browse files
committed
feat: add backdrop static option support
1 parent 9624a96 commit 078030b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/coreui-react/src/components/offcanvas/COffcanvas.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface COffcanvasProps extends HTMLAttributes<HTMLDivElement> {
1111
/**
1212
* Apply a backdrop on body while offcanvas is open.
1313
*/
14-
backdrop?: boolean
14+
backdrop?: boolean | string
1515
/**
1616
* A string of all className you want applied to the base component.
1717
*/
@@ -105,6 +105,11 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
105105
const handleDismiss = () => {
106106
setVisible(false)
107107
}
108+
const handleBackdropDismiss = () => {
109+
if (backdrop !== 'static') {
110+
setVisible(false)
111+
}
112+
}
108113

109114
const handleKeyDown = useCallback(
110115
(event: React.KeyboardEvent<HTMLDivElement>) => {
@@ -154,15 +159,15 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
154159
createPortal(
155160
<CBackdrop
156161
className="offcanvas-backdrop"
157-
onClick={handleDismiss}
162+
onClick={handleBackdropDismiss}
158163
visible={_visible}
159164
/>,
160165
document.body,
161166
)
162167
: backdrop && (
163168
<CBackdrop
164169
className="offcanvas-backdrop"
165-
onClick={handleDismiss}
170+
onClick={handleBackdropDismiss}
166171
visible={_visible}
167172
/>
168173
)}
@@ -172,7 +177,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
172177
)
173178

174179
COffcanvas.propTypes = {
175-
backdrop: PropTypes.bool,
180+
backdrop: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
176181
children: PropTypes.node,
177182
className: PropTypes.string,
178183
keyboard: PropTypes.bool,

0 commit comments

Comments
 (0)