question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModalDrawer does not prevent tab navigation in background

See original GitHub issue

See this example code:

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.DrawerValue
import androidx.compose.material.ModalDrawer
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.rememberDrawerState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.singleWindowApplication

fun main() = singleWindowApplication(WindowState(size = DpSize(300.dp,100.dp))) {
    val drawerState = rememberDrawerState(DrawerValue.Open)
    ModalDrawer(
        drawerState = drawerState,
        drawerContent = {
            TextButton(onClick = {}) {
                Text("Focusable as expected")
            }
        }
    ) {
        Box(Modifier.fillMaxSize()) {
            TextButton(onClick = {}, modifier = Modifier.align(Alignment.TopEnd)) {
                Text("Should not be focusable")
            }
        }
    }
}

Mouse interaction with the items in the background is prevented, but keyboard interaction (via Tab navigation and, e.g., Enter to click) is not:

image

I guess this might not be limited to Compose for Desktop, since focus management is not platform specific from what I could tell from the source code. In case it also affects Jetpack Compose, I’m not sure where to raise the issue.

Also, I didn’t find any way to conveniently disable all interaction (including tab navigation) of some composable including its children. Using Modifier.focusProperties { canFocus = false } on the first child in content did disable focus reception for some children, but not for all.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

1reaction
ialokimcommented, Dec 7, 2022
1reaction
dima-avdeev-jbcommented, Nov 30, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can restrict the tab key press only within the modal popup ...
But when modal opened i want only the focus navigate within the modal popup. Working on Angular4, HTML5 project. Better if we find...
Read more >
Navigation drawer – Material Design 3
Navigation drawers provide access to destinations in your app.
Read more >
androidx.compose.material - Android Developers
Navigation drawer, ModalDrawer, Modal navigation drawer ... If persistentAppBar is set to false , then the backdrop will not show the app bar...
Read more >
How to create a Navigation Drawer with Jetpack Compose
Creating the Navigation Drawer ... First, we going to create the menu items. We go to the project name folder and right-click, select...
Read more >
Navigation Drawer using Jetpack Compose - ProAndroidDev
Jetpack Compose is the newest coolest Android toolkit from Google to ... To add a navigation drawer, we are using ModalDrawer composable ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found