Skip to content

Commit 2495c0b

Browse files
committed
Add: SuperDropdown will be "selected" when the popup is expanded.
1 parent 2836b0b commit 2495c0b

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDropdown.kt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import androidx.compose.foundation.Image
44
import androidx.compose.foundation.background
55
import androidx.compose.foundation.clickable
66
import androidx.compose.foundation.gestures.detectTapGestures
7+
import androidx.compose.foundation.interaction.FocusInteraction
8+
import androidx.compose.foundation.interaction.MutableInteractionSource
79
import androidx.compose.foundation.layout.Arrangement
810
import androidx.compose.foundation.layout.Row
911
import androidx.compose.foundation.layout.WindowInsets
@@ -21,6 +23,7 @@ import androidx.compose.foundation.layout.statusBars
2123
import androidx.compose.foundation.layout.width
2224
import androidx.compose.foundation.layout.windowInsetsPadding
2325
import androidx.compose.foundation.lazy.LazyColumn
26+
import androidx.compose.material.ripple
2427
import androidx.compose.runtime.Composable
2528
import androidx.compose.runtime.LaunchedEffect
2629
import androidx.compose.runtime.MutableState
@@ -112,6 +115,18 @@ fun SuperDropdown(
112115
var dropdownOffsetYPx by remember { mutableStateOf(0) }
113116
var componentHeightPx by remember { mutableStateOf(0) }
114117
var componentWidthPx by remember { mutableStateOf(0) }
118+
val interactionSource = remember { MutableInteractionSource() }
119+
val focus = remember { mutableStateOf<FocusInteraction.Focus?>(null) }
120+
121+
LaunchedEffect(isDropdownExpanded.value) {
122+
if (isDropdownExpanded.value) {
123+
focus.value = FocusInteraction.Focus().also {
124+
interactionSource.emit(it)
125+
}
126+
} else {
127+
focus.value?.let { interactionSource.emit(FocusInteraction.Unfocus(it)) }
128+
}
129+
}
115130

116131
BasicComponent(
117132
modifier = modifier
@@ -134,6 +149,15 @@ fun SuperDropdown(
134149
componentHeightPx = coordinates.size.height
135150
componentWidthPx = coordinates.size.width
136151
}
152+
}
153+
.clickable(
154+
interactionSource = interactionSource,
155+
indication = ripple()
156+
) {
157+
if (enabled) {
158+
isDropdownExpanded.value = enabled
159+
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
160+
}
137161
},
138162
insideMargin = insideMargin,
139163
title = title,
@@ -157,12 +181,6 @@ fun SuperDropdown(
157181
contentDescription = null
158182
)
159183
},
160-
onClick = {
161-
if (enabled) {
162-
isDropdownExpanded.value = enabled
163-
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
164-
}
165-
},
166184
enabled = enabled
167185
)
168186
if (isDropdownExpanded.value) {

0 commit comments

Comments
 (0)