Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow home/end key default behavior inside `ComboboxInput` when `Combobox` is closed ([#3798](https://github.com/tailwindlabs/headlessui/pull/3798))
- Ensure interacting with a `Dialog` on iOS works after interacting with a disallowed area ([#3801](https://github.com/tailwindlabs/headlessui/pull/3801))
- Freeze Listbox values as soon as possible when closing ([#3802](https://github.com/tailwindlabs/headlessui/pull/3802))
- Ensure refs are forwarded when freezing data ([#3390](https://github.com/tailwindlabs/headlessui/pull/3390))

## [2.2.8] - 2025-09-12

Expand Down
14 changes: 12 additions & 2 deletions packages/@headlessui-react/src/internal/frozen.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import React, { useState } from 'react'
import React, { cloneElement, isValidElement, useState } from 'react'

export function Frozen({ children, freeze }: { children: React.ReactNode; freeze: boolean }) {
function FrozenFn(
{ children, freeze }: { children: React.ReactNode; freeze: boolean },
ref: React.ForwardedRef<HTMLElement>
) {
let contents = useFrozenData(freeze, children)

if (isValidElement(contents)) {
return cloneElement(contents as React.ReactElement, { ref })
}

return <>{contents}</>
}

export const Frozen = React.forwardRef(FrozenFn)

export function useFrozenData<T>(freeze: boolean, data: T) {
let [frozenValue, setFrozenValue] = useState(data)

Expand Down