KeepPopupOpenStrategy

abstract class KeepPopupOpenStrategy(defaultValue: Boolean = false)(source)

A contract for a strategy that determines whether a popup should stay open or not.

The strategy will be informed about some popup element, which it can query / listen to its events to determine if it should be kept open or not.

If users want to provide their own strategy, they should instantiate a class that implements this class and remember it somewhere:

val manualStrategy = remember { KeepPopupOpenStrategy.manual() }
Popover(..., keepOpenStrategy = manualStrategy) {
Button(onClick = { manualStrategy.shouldKeepOpen = false }) { Text("Close") }
}

Children classes should implement this and fire emitShouldKeepOpen when they detect some change that determines if the popup should stay open or not.

Parameters

defaultValue

The initial "keep open" value for this strategy. Defaults to false. Note that the same strategy can be reused for multiple lifecycles of a popup opening and closing, so each time it is reset, it will set its state back to this default value.

Inheritors

Constructors

Link copied to clipboard
constructor(defaultValue: Boolean = false)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val keepOpenFlow: StateFlow<Boolean>

A flow which represents a stream of decisions by this strategy on whether the popup should stay open or not.

Link copied to clipboard

A readable convenience property that queries the underlying state flow.

Functions

Link copied to clipboard
fun init(popupElement: HTMLElement)

Initialize any state needed by the strategy.

Link copied to clipboard

A strategy that observes another strategy and reflects its state.

Link copied to clipboard
Link copied to clipboard
fun reset()

Reset the strategy to its initial state.