From aae84e1c78ed7255bb73947fdd14a5979333b048 Mon Sep 17 00:00:00 2001 From: Siddharth Agarwal Date: Thu, 12 Oct 2023 11:27:03 +0530 Subject: [PATCH] make whole component clickable to open dropdown --- .../designsystem/component/InputDropDown.kt | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDropDown.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDropDown.kt index 340509e21..a4a09029e 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDropDown.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDropDown.kt @@ -1,5 +1,8 @@ package org.hisp.dhis.mobile.ui.designsystem.component +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.ArrowDropDown import androidx.compose.material.icons.outlined.Cancel @@ -9,6 +12,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.onFocusChanged @@ -67,17 +71,30 @@ fun InputDropDown( } }, inputField = { - Text( - modifier = Modifier.testTag("INPUT_DROPDOWN_TEXT"), - text = selectedItem ?: "", - style = MaterialTheme.typography.bodyLarge.copy( - color = if (state != InputShellState.DISABLED) { - TextColor.OnSurface - } else { - TextColor.OnDisabledSurface - }, - ), - ) + Box { + Text( + modifier = Modifier + .testTag("INPUT_DROPDOWN_TEXT") + .fillMaxWidth(), + text = selectedItem ?: "", + style = MaterialTheme.typography.bodyLarge.copy( + color = if (state != InputShellState.DISABLED) { + TextColor.OnSurface + } else { + TextColor.OnDisabledSurface + }, + ), + ) + Box( + modifier = Modifier + .matchParentSize() + .alpha(0f) + .clickable(onClick = { + focusRequester.requestFocus() + onArrowDropDownButtonClicked.invoke() + }), + ) + } }, primaryButton = { IconButton(