Skip to content

Commit c0368db

Browse files
author
Luke Bowerman
authored
Deal with scenario where Dialog only has isOpen specified (#1557)
1 parent 43fd16b commit c0368db

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.9.18] - 2020-10-12
9+
10+
- `useDialog` needs to support scenario it is controlled but `onClose` isn't specified
11+
812
## [0.9.17] - 2020-10-12
913

1014
## Added

packages/components/src/Dialog/Dialog.test.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
*/
2626

2727
import 'jest-styled-components'
28-
import React from 'react'
28+
import React, { useState } from 'react'
2929
import { renderWithTheme } from '@looker/components-test-utils'
3030
import {
3131
screen,
3232
fireEvent,
3333
waitForElementToBeRemoved,
3434
} from '@testing-library/react'
3535
import { SimpleContent } from '../__mocks__/DialogContentSimple'
36+
import { DialogMediumContent } from '../__mocks__/DialogMediumContent'
3637
import { Dialog } from './Dialog'
3738
import { DialogManager } from './DialogManager'
3839
import {
@@ -159,9 +160,6 @@ describe('Dialog', () => {
159160
await waitForElementToBeRemoved(() => screen.getByText('Dialog content'))
160161
})
161162

162-
/**
163-
* NOTE: All other tests assume a "uncontrolled" version of Dialog.
164-
*/
165163
test('Controlled', async () => {
166164
renderWithTheme(<Controlled />)
167165

@@ -176,6 +174,26 @@ describe('Dialog', () => {
176174
await waitForElementToBeRemoved(() => screen.getByText(/We the People/))
177175
})
178176

177+
test('Controlled no callbacks', async () => {
178+
const SimpleControlled = () => {
179+
const [isOpen, setOpen] = useState(false)
180+
181+
return (
182+
<>
183+
<Dialog content={<DialogMediumContent />} isOpen={isOpen} />
184+
<button onClick={() => setOpen(true)}>Open Dialog</button>
185+
</>
186+
)
187+
}
188+
189+
renderWithTheme(<SimpleControlled />)
190+
191+
// Open Dialog
192+
const link = screen.getByText('Open Dialog')
193+
fireEvent.click(link)
194+
expect(screen.queryByText(/We the People/)).toBeInTheDocument()
195+
})
196+
179197
test('Controlled - no children', async () => {
180198
renderWithTheme(<ControlledNoChildren />)
181199

packages/components/src/Dialog/useDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ export const useDialog = ({
173173
/**
174174
* LEGACY SUPPORT
175175
* Eventually we need to deprecate support for `isOpen` without specifying a `setOpen`
176-
* being explicitly so we can unwind this semi-controlled state.
176+
* explicitly so we can unwind this semi-controlled state.
177177
*/
178-
const isPartiallyControlled = !!onClose && controlledIsOpen !== undefined
178+
const isPartiallyControlled = controlledIsOpen !== undefined
179179

180180
const isOpen =
181181
isPartiallyControlled || isControlled

0 commit comments

Comments
 (0)