-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
DropdownMenu gets positioned on the opposite side when anchored outside the window #3129
DropdownMenu gets positioned on the opposite side when anchored outside the window #3129
Comments
Can you post a complete working snippet? I'm having trouble reproducing it because when the menu is showing, the underlying UI is not receiving events, so it's not possible to scroll. |
@m-sasha Yes, sure. I forgot to add a horizontal scrollbar and make the dropdown menu unfocusable. Please try the updated code snippet in the issue description. |
Hmm. I changed the code a bit to move the dropdown to the left, but it seems to work fine in Compose 1.4.0, Compose 1.5.0-dev1036 and also in the very latest commit on our development branch: Screen.Recording.2023-05-08.at.20.35.10.mp4Does this exact code manifest the bug for you?
|
@m-sasha Okay, interesting. I tried your code, and fun main() = application {
Window(onCloseRequest = ::exitApplication) {
val horizontalScrollState = rememberScrollState()
var isMenuExpanded by remember { mutableStateOf(false) }
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
Box {
Column(modifier = Modifier.horizontalScroll(horizontalScrollState)) {
Row(modifier = Modifier.width(2000.dp)) {
Spacer(Modifier.width(100.dp))
Column(modifier = Modifier.padding(16.dp)) {
Button(
modifier = Modifier.width(160.dp),
onClick = {
isMenuExpanded = !isMenuExpanded
}
) {
Text("Click me")
}
DropdownMenu(
modifier = Modifier.width(160.dp),
expanded = isMenuExpanded,
onDismissRequest = {
isMenuExpanded = false
},
focusable = false
) {
repeat(10) {
DropdownMenuItem(
onClick = {
isMenuExpanded = false
}
) {
Text("Item $it")
}
}
}
}
}
}
HorizontalScrollbar(
modifier = Modifier.fillMaxWidth().align(Alignment.BottomStart),
adapter = rememberScrollbarAdapter(
scrollState = horizontalScrollState
)
)
}
}
}
} Screen-Recording-2023-05-08-at-9.08.18-PM.mp4 |
That code also works for me without the bug manifesting. Can you post all the code, including imports? |
@m-sasha Okay, I discovered the issue. It turns out changing the default locale outside a import androidx.compose.foundation.HorizontalScrollbar
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import java.util.*
fun main() = application {
// Set arabic locale.
Locale.setDefault(Locale("ar", "EG"))
Window(onCloseRequest = ::exitApplication) {
// Having it here instead works.
// Locale.setDefault(Locale("ar", "EG"))
val horizontalScrollState = rememberScrollState()
var isMenuExpanded by remember { mutableStateOf(false) }
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
Box {
Column(modifier = Modifier.horizontalScroll(horizontalScrollState)) {
Row(modifier = Modifier.width(2000.dp)) {
Spacer(Modifier.width(100.dp))
Column(modifier = Modifier.padding(16.dp)) {
Button(
modifier = Modifier.width(160.dp),
onClick = {
isMenuExpanded = !isMenuExpanded
}
) {
Text("Click me")
}
DropdownMenu(
modifier = Modifier.width(160.dp),
expanded = isMenuExpanded,
onDismissRequest = {
isMenuExpanded = false
},
focusable = false
) {
repeat(10) {
DropdownMenuItem(
onClick = {
isMenuExpanded = false
}
) {
Text("Item $it")
}
}
}
}
}
}
HorizontalScrollbar(
modifier = Modifier.fillMaxWidth().align(Alignment.BottomStart),
adapter = rememberScrollbarAdapter(
scrollState = horizontalScrollState
)
)
}
}
}
} |
Ok, I have a reproducer, which amusingly doesn't require a locale change, nor
Screen.Recording.2023-05-08.at.21.27.44.mp4With your permission, I will change the issue title. |
Nice bug find. 😮 Sure. |
Note that there are actually two problems seen here:
|
Note that even with this fix, it will still not work correctly with RTL layout direction until "LocalLayoutDirection isn't propagated into Popup" is also fixed. |
Thanks for the update! |
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks. |
Describe the bug
DropdownMenu gets positioned incorrectly for RTL layout direction when moved out of screen bounds.
Code Snippet
Affected platforms
All
Versions
To Reproduce
DropdownMenu
inside a horizontal container with RTL layout direction.Expected Behavior
The dropdown menu should remain fixed to the right end of the window when the layout direction is RTL.
Actual Behavior
The dropdown menu gets positioned to the left of the window when the layout direction is RTL.
Screenshot
Screen-Recording-2023-05-06-at-4.11.25-AM.mp4
The text was updated successfully, but these errors were encountered: