Skip to content

Commit c8cf26f

Browse files
authored
Prefer incoming open prop over OpenClosed state (#1360)
* prefer incoming `open` prop over OpenClosed state * update changelog
1 parent fe034b4 commit c8cf26f

File tree

3 files changed

+4
-17
lines changed

3 files changed

+4
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3737
- Allow `Enter` for form submit in `RadioGroup`, `Switch` and `Combobox` improvements ([#1285](https://github.com/tailwindlabs/headlessui/pull/1285))
3838
- add React 18 compatibility ([#1326](https://github.com/tailwindlabs/headlessui/pull/1326))
3939
- Add explicit `multiple` prop ([#1355](https://github.com/tailwindlabs/headlessui/pull/1355))
40+
- Prefer incoming `open` prop over OpenClosed state ([#1360](https://github.com/tailwindlabs/headlessui/pull/1360))
4041

4142
### Added
4243

@@ -78,6 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7879
- Allow `Enter` for form submit in `RadioGroup`, `Switch` and `Combobox` improvements ([#1285](https://github.com/tailwindlabs/headlessui/pull/1285))
7980
- Add explicit `multiple` prop ([#1355](https://github.com/tailwindlabs/headlessui/pull/1355))
8081
- fix `nullable` prop for Vue ([2b109548b1a94a30858cf58c8f525554a1c12cbb](https://github.com/tailwindlabs/headlessui/commit/2b109548b1a94a30858cf58c8f525554a1c12cbb))
82+
- Prefer incoming `open` prop over OpenClosed state ([#1360](https://github.com/tailwindlabs/headlessui/pull/1360))
8183

8284
### Added
8385

packages/@headlessui-react/src/components/dialog/dialog.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,6 @@ let DialogRoot = forwardRefWithAs(function Dialog<
173173
}
174174

175175
let dialogState = open ? DialogStates.Open : DialogStates.Closed
176-
let visible = (() => {
177-
if (usesOpenClosedState !== null) {
178-
return usesOpenClosedState === State.Open
179-
}
180-
181-
return dialogState === DialogStates.Open
182-
})()
183176

184177
let [state, dispatch] = useReducer(stateReducer, {
185178
titleId: null,
@@ -357,7 +350,7 @@ let DialogRoot = forwardRefWithAs(function Dialog<
357350
slot,
358351
defaultTag: DEFAULT_DIALOG_TAG,
359352
features: DialogRenderFeatures,
360-
visible,
353+
visible: dialogState === DialogStates.Open,
361354
name: 'Dialog',
362355
})}
363356
</DescriptionProvider>

packages/@headlessui-vue/src/components/dialog/dialog.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ export let Dialog = defineComponent({
113113
}
114114

115115
let dialogState = computed(() => (open.value ? DialogStates.Open : DialogStates.Closed))
116-
let visible = computed(() => {
117-
if (usesOpenClosedState !== null) {
118-
return usesOpenClosedState.value === State.Open
119-
}
120-
121-
return dialogState.value === DialogStates.Open
122-
})
123-
124116
let enabled = computed(() => dialogState.value === DialogStates.Open)
125117

126118
let hasNestedDialogs = computed(() => nestedDialogCount.value > 1) // 1 is the current dialog
@@ -307,7 +299,7 @@ export let Dialog = defineComponent({
307299
slot,
308300
attrs,
309301
slots,
310-
visible: visible.value,
302+
visible: dialogState.value === DialogStates.Open,
311303
features: Features.RenderStrategy | Features.Static,
312304
name: 'Dialog',
313305
})

0 commit comments

Comments
 (0)