diff --git a/plugins/woocommerce-blocks/assets/js/base/components/drawer/close-button.tsx b/plugins/woocommerce-blocks/assets/js/base/components/drawer/close-button.tsx new file mode 100644 index 00000000000..bbd61a45102 --- /dev/null +++ b/plugins/woocommerce-blocks/assets/js/base/components/drawer/close-button.tsx @@ -0,0 +1,7 @@ +const DrawerCloseButton = () => { + // The Drawer component will use a portal to render the close button inside + // this div. + return
; +}; + +export default DrawerCloseButton; diff --git a/plugins/woocommerce-blocks/assets/js/base/components/drawer/index.tsx b/plugins/woocommerce-blocks/assets/js/base/components/drawer/index.tsx index 938db7d3bae..17cd69461ec 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/drawer/index.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/drawer/index.tsx @@ -7,7 +7,7 @@ */ import classNames from 'classnames'; import { useDebounce } from 'use-debounce'; -import type { ForwardedRef, KeyboardEvent } from 'react'; +import type { ForwardedRef, KeyboardEvent, RefObject } from 'react'; import { __ } from '@wordpress/i18n'; import { createPortal, @@ -41,6 +41,33 @@ interface DrawerProps { slideOut?: boolean; } +interface CloseButtonPortalProps { + onClick: () => void; + contentRef: RefObject< HTMLDivElement >; +} + +const CloseButtonPortal = ( { + onClick, + contentRef, +}: CloseButtonPortalProps ) => { + const closeButtonWrapper = contentRef?.current?.querySelector( + '.wc-block-components-drawer__close-wrapper' + ); + + return closeButtonWrapper + ? createPortal( +