Skip to content

Commit

Permalink
Fix Dropdown disabled colors (#674)
Browse files Browse the repository at this point in the history
* add disabled Dropdown sample to IDE sample

Signed-off-by: Ivan Morgillo <[email protected]>

* fix #668

Signed-off-by: Ivan Morgillo <[email protected]>

* make the formatter happy

---------

Signed-off-by: Ivan Morgillo <[email protected]>
  • Loading branch information
hamen authored Nov 6, 2024
1 parent bf911c3 commit 52a6d49
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ private fun RowScope.ColumnOne() {
) {
Text("Selected item $selectedItem")
}
Dropdown(
enabled = false,
menuContent = {
selectableItem(selectedItem == 0, onClick = { selectedItem = 0 }) { Text("Hello") }

separator()

selectableItem(selectedItem == 1, onClick = { selectedItem = 1 }) { Text("World") }
},
) {
Text("Selected item $selectedItem")
}

Row(horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.CenterVertically) {
var clicks1 by remember { mutableIntStateOf(0) }
Expand Down
16 changes: 13 additions & 3 deletions ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Dropdown.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.input.InputMode
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
Expand All @@ -41,8 +43,10 @@ import org.jetbrains.jewel.foundation.state.CommonStateBitMask.Pressed
import org.jetbrains.jewel.foundation.state.FocusableComponentState
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.foundation.theme.LocalContentColor
import org.jetbrains.jewel.foundation.theme.LocalTextStyle
import org.jetbrains.jewel.ui.Outline
import org.jetbrains.jewel.ui.component.styling.DropdownStyle
import org.jetbrains.jewel.ui.disabled
import org.jetbrains.jewel.ui.focusOutline
import org.jetbrains.jewel.ui.outline
import org.jetbrains.jewel.ui.painter.hints.Stateful
Expand Down Expand Up @@ -115,7 +119,10 @@ public fun Dropdown(
.onSizeChanged { componentWidth = it.width },
contentAlignment = Alignment.CenterStart,
) {
CompositionLocalProvider(LocalContentColor provides colors.contentFor(dropdownState).value) {
CompositionLocalProvider(
LocalContentColor provides colors.contentFor(dropdownState).value,
LocalTextStyle provides LocalTextStyle.current.copy(color = colors.contentFor(dropdownState).value),
) {
Box(
modifier =
Modifier.fillMaxWidth().padding(style.metrics.contentPadding).padding(end = arrowMinSize.width),
Expand All @@ -127,10 +134,13 @@ public fun Dropdown(
modifier = Modifier.size(arrowMinSize).align(Alignment.CenterEnd),
contentAlignment = Alignment.Center,
) {
val alpha = if (dropdownState.isEnabled) 1f else 0.5f
val colorFilter = if (dropdownState.isEnabled) null else ColorFilter.disabled()
Icon(
modifier = Modifier.alpha(alpha),
key = style.icons.chevronDown,
contentDescription = null,
tint = colors.iconTintFor(dropdownState).value,
contentDescription = "Dropdown Chevron",
colorFilter = colorFilter,
hint = Stateful(dropdownState),
)
}
Expand Down

0 comments on commit 52a6d49

Please sign in to comment.