commit a9cbbb3c47b4fd0526645118973d9786f06398a4
parent 0a5135c08676253cf8c61526e56d8a92c7bfcfa6
Author: Harrison Oglesby <oglesby.harrison@gmail.com>
Date: Thu, 13 Nov 2025 17:12:25 +0000
Bug 1999845 - Open keyboard when starting settings search r=android-reviewers,petru
Differential Revision: https://phabricator.services.mozilla.com/D272369
Diffstat:
1 file changed, 34 insertions(+), 16 deletions(-)
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/settingssearch/SettingsSearchBar.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/settingssearch/SettingsSearchBar.kt
@@ -11,11 +11,14 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
@@ -42,6 +45,7 @@ fun SettingsSearchBar(
) {
val state by store.observeAsComposableState { it }
var searchQuery by remember { mutableStateOf(state.searchQuery) }
+ val focusRequester = remember { FocusRequester() }
TopAppBar(
modifier = Modifier
@@ -54,7 +58,8 @@ fun SettingsSearchBar(
store.dispatch(SettingsSearchAction.SearchQueryUpdated(value))
},
modifier = Modifier
- .fillMaxWidth(),
+ .fillMaxWidth()
+ .focusRequester(focusRequester),
placeholder = stringResource(R.string.settings_search_title),
singleLine = true,
errorText = stringResource(R.string.settings_search_error_message),
@@ -68,21 +73,12 @@ fun SettingsSearchBar(
is SettingsSearchState.SearchInProgress,
is SettingsSearchState.NoSearchResults,
-> {
- IconButton(
- onClick = {
- searchQuery = ""
- store.dispatch(SettingsSearchAction.SearchQueryUpdated(""))
- },
- contentDescription = stringResource(
- R.string.content_description_settings_search_clear_search,
- ),
- ) {
- Icon(
- painter = painterResource(iconsR.drawable.mozac_ic_cross_circle_fill_24),
- contentDescription = null,
- tint = FirefoxTheme.colors.textPrimary,
- )
- }
+ ClearTextButton(
+ onClick = {
+ searchQuery = ""
+ store.dispatch(SettingsSearchAction.SearchQueryUpdated(""))
+ },
+ )
}
else -> Unit
}
@@ -111,4 +107,26 @@ fun SettingsSearchBar(
bottom = 0.dp,
),
)
+
+ SideEffect {
+ focusRequester.requestFocus()
+ }
+}
+
+@Composable
+private fun ClearTextButton(
+ onClick: () -> Unit,
+) {
+ IconButton(
+ onClick = onClick,
+ contentDescription = stringResource(
+ R.string.content_description_settings_search_clear_search,
+ ),
+ ) {
+ Icon(
+ painter = painterResource(iconsR.drawable.mozac_ic_cross_circle_fill_24),
+ contentDescription = null,
+ tint = FirefoxTheme.colors.textPrimary,
+ )
+ }
}