-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve UX by freezing
<ComboboxOptions />
component while closing (#…
…3304) * add internal `Frozen` component and `useFrozenData` hook * implement frozen state for the `Combobox` component When the `Combobox` is in a closed state, but still visible (aka transitioning out), then we want to freeze the `children` of the `ComboboxOptions`. This way we still look at the old list while transitioning out and you can safely reset any `state` that filters the options in the `onClose` callback. Note: we want to only freeze the children of the `ComboboxOptions`, not the `ComboboxOptions` itself because we are still applying the necessary data attributes to make the transition happen. Similarly, if you are using the `virtual` prop, then we only freeze the `virtual.options` and render the _old_ list while transitioning out. * use `useFrozenData` in `Listbox` component * use `data-*` attributes and `transition` prop to simplify playgrounds * update changelog * improve comment * simplify frozen conditions * use existing variable for frozen state
- Loading branch information
1 parent
29e7d94
commit 1c3f9a6
Showing
7 changed files
with
203 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React, { useState } from 'react' | ||
|
||
export function Frozen({ children, freeze }: { children: React.ReactNode; freeze: boolean }) { | ||
let contents = useFrozenData(freeze, children) | ||
return <>{contents}</> | ||
} | ||
|
||
export function useFrozenData<T>(freeze: boolean, data: T) { | ||
let [frozenValue, setFrozenValue] = useState(data) | ||
|
||
// We should keep updating the frozen value, as long as we shouldn't freeze | ||
// the value yet. The moment we should freeze the value we stop updating it | ||
// which allows us to reference the "previous" (thus frozen) value. | ||
if (!freeze && frozenValue !== data) { | ||
setFrozenValue(data) | ||
} | ||
|
||
return freeze ? frozenValue : data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.