From 0b4c50d67bbff5560922853652821e43590dba60 Mon Sep 17 00:00:00 2001 From: Ashley Ryan Date: Tue, 2 Aug 2022 14:53:01 -0400 Subject: [PATCH] fix(modal): react - convert hidden false values to undefined fixes #122 --- projects/react/src/modal/index.test.tsx | 14 +++++++++ projects/react/src/modal/index.tsx | 40 +++++++++++++++++++------ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/projects/react/src/modal/index.test.tsx b/projects/react/src/modal/index.test.tsx index c9a42cd12..d80a76258 100644 --- a/projects/react/src/modal/index.test.tsx +++ b/projects/react/src/modal/index.test.tsx @@ -23,6 +23,20 @@ describe('CdsModal', () => { expect(await screen.findByText('My Modal')).toBeInTheDocument(); expect(document.querySelector('cds-modal-content')).toHaveTextContent(/Lorem Ipsum/); expect(document.querySelector('cds-modal-actions')).toHaveTextContent(/Foo/); + + expect(document.querySelector('cds-modal')).not.toHaveAttribute('hidden'); + }); + + it('has attribute hidden when hidden', () => { + render( + + ); + + expect(document.querySelector('cds-modal')).toHaveAttribute('hidden', 'true'); }); it('snapshot', () => { diff --git a/projects/react/src/modal/index.tsx b/projects/react/src/modal/index.tsx index 70489ba2f..e798b6d27 100644 --- a/projects/react/src/modal/index.tsx +++ b/projects/react/src/modal/index.tsx @@ -10,15 +10,37 @@ import { createComponent } from '@lit-labs/react'; import * as React from 'react'; import { logReactVersion } from '../utils/index.js'; -export const CdsModal = createComponent( - React, - 'cds-modal', - Modal, - { - onCloseChange: 'closeChange', - onCdsMotionChange: 'cdsMotionChange', - }, - 'CdsModal' +/** + * Converts a false value for `hidden` to `undefined` so it doesn't get rendered in the DOM + * + * There is an open issue where lit/react passes the false value to the element in the dom + * this isn't valid per the spec for boolean attributes. + * + * We mostly work around it with CSS, but it's still causing some problems with the modal overlay + * REMOVE THIS WHEN THE FOLLOWING ISSUE IS RESOLVED (also remove all of the CSS fixes) + * + * https://github.com/lit/lit/issues/3053 + * @param CdsButton + * @returns CdsButton + */ +function removeFalseHiddenProp

(Component: React.ComponentType

) { + return (props: P) => { + const { hidden } = props; + return