Skip to content

Add focusable parameter to Flyout and defaults to true #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ object AutoSuggestBoxDefaults {
paddingToAnchor = PaddingValues()
),
contentPadding = PaddingValues(),
focusable = false,
content = {
CompactMode(enabled = compactMode) {
val adapter = rememberScrollbarAdapter(state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ class DialogSize(
*
* @param visible Controls the visibility of the dialog. When `true`, the dialog is shown; otherwise, it's hidden.
* @param size The size of the dialog, defining its minimum and maximum width. Defaults to [DialogSize.Standard].
* @param properties Additional properties for the dialog's popup, such as focusability. Defaults to non-focusable.
* @param properties Additional properties for the dialog's popup, such as focusability.
* @param content The composable content to display within the dialog.
*/
@Composable
fun FluentDialog(
visible: Boolean,
size: DialogSize = DialogSize.Standard,
properties: PopupProperties = PopupProperties(focusable = false),
properties: PopupProperties = PopupProperties(focusable = true),
content: @Composable () -> Unit
) {
val visibleState = remember { MutableTransitionState(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ import io.github.jpy.wangposefluent.background.Layer
* @param onDismissRequest Called when the user requests to dismiss the menu, such as by clicking
* outside the menu's bounds.
* @param modifier The modifier to be applied to the menu.
* @param focusable Whether the menu should be focusable. This affects whether the menu can be
* navigated using the keyboard.
* @param onPreviewKeyEvent Called when a key event is received by the menu, before it is dispatched
* to the focusable content. Return true to consume the event.
* @param onKeyEvent Called when a key event is received by the menu, after it is dispatched to
Expand All @@ -69,7 +67,6 @@ fun DropdownMenu(
expanded: Boolean,
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
focusable: Boolean = false,
onPreviewKeyEvent: ((KeyEvent) -> Boolean) = { false },
onKeyEvent: ((KeyEvent) -> Boolean) = { false },
offset: DpOffset = DpOffset(0.dp, 0.dp), // TODO: Offset
Expand All @@ -84,7 +81,7 @@ fun DropdownMenu(
val popupPositionProvider = DropdownMenuPositionProvider(density, offset)

Popup(
properties = PopupProperties(focusable = focusable),
properties = PopupProperties(focusable = true),
onDismissRequest = onDismissRequest,
onKeyEvent = onKeyEvent,
onPreviewKeyEvent = onPreviewKeyEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import io.github.jpy.wangposefluent.background.calculateBorderPadding
* @param onPreviewKeyEvent An optional callback invoked when a key event is dispatched to the flyout
* before it is dispatched to any focused view. If not null, it will be
* focusable.
* @param focusable Determines whether the flyout is focusable. Setting to false allows user to interact
* with the outside area of the flyout. Defaults to `true`.
* @param content A composable lambda representing the main content within the container.
* It also has access to the [FlyoutContainerScope].
*/
Expand All @@ -83,6 +85,7 @@ fun FlyoutContainer(
adaptivePlacement: Boolean = false,
onKeyEvent: ((keyEvent: KeyEvent) -> Boolean)? = null,
onPreviewKeyEvent: ((keyEvent: KeyEvent) -> Boolean)? = null,
focusable: Boolean = true,
content: @Composable FlyoutContainerScope.() -> Unit
) {
BasicFlyoutContainer(
Expand All @@ -94,6 +97,7 @@ fun FlyoutContainer(
adaptivePlacement = adaptivePlacement,
onKeyEvent = onKeyEvent,
onPreviewKeyEvent = onPreviewKeyEvent,
focusable = focusable,
content = { flyout() }
)
},
Expand Down Expand Up @@ -181,6 +185,8 @@ enum class FlyoutPlacement {
* @param onPreviewKeyEvent Optional callback to preview key events before they are dispatched to
* the flyout's content. Return `true` to consume the event, `false` to allow it to propagate.
* Defaults to `null`.
* @param focusable Determines whether the flyout is focusable. Setting to false allows user to interact
* with the outside area of the flyout. Defaults to `true`.
* @param content The content to be displayed within the flyout.
*/
@Composable
Expand All @@ -193,6 +199,7 @@ fun Flyout(
shape: Shape = FluentTheme.shapes.overlay,
onKeyEvent: ((keyEvent: KeyEvent) -> Boolean)? = null,
onPreviewKeyEvent: ((keyEvent: KeyEvent) -> Boolean)? = null,
focusable: Boolean = true,
content: @Composable () -> Unit
) {
BasicFlyout(
Expand All @@ -206,6 +213,7 @@ fun Flyout(
shape = shape,
onKeyEvent = onKeyEvent,
onPreviewKeyEvent = onPreviewKeyEvent,
focusable = focusable,
content = content
)
}
Expand All @@ -221,6 +229,7 @@ internal fun BasicFlyout(
positionProvider: FlyoutPositionProvider = rememberFlyoutPositionProvider(),
onKeyEvent: ((keyEvent: KeyEvent) -> Boolean)? = null,
onPreviewKeyEvent: ((keyEvent: KeyEvent) -> Boolean)? = null,
focusable: Boolean = true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
focusable: Boolean = true,
focusable: Boolean = onKeyEvent != null || onPreviewKeyEvent != null,

content: @Composable () -> Unit
) {
val visibleState = remember {
Expand All @@ -232,7 +241,7 @@ internal fun BasicFlyout(
onDismissRequest = onDismissRequest,
properties = PopupProperties(
clippingEnabled = false,
focusable = onKeyEvent != null || onPreviewKeyEvent != null
focusable = focusable
),
popupPositionProvider = positionProvider,
onKeyEvent = onKeyEvent,
Expand Down Expand Up @@ -428,7 +437,7 @@ private class FlyoutContainerScopeImpl(
* Clicking outside of the flyout will set `isFlyoutVisible` to false, hiding the flyout.
*/
@OptIn(ExperimentalFluentApi::class)
interface FlyoutContainerScope: FlyoutAnchorScope {
interface FlyoutContainerScope : FlyoutAnchorScope {

var isFlyoutVisible: Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ internal fun MenuFlyout(
positionProvider = positionProvider,
contentPadding = PaddingValues(vertical = 3.dp),
onKeyEvent = onKeyEvent,
onPreviewKeyEvent = onPreviewKeyEvent
onPreviewKeyEvent = onPreviewKeyEvent,
focusable = false
) {
val state = rememberScrollState()
ScrollbarContainer(
Expand Down