Skip to content

Commit

Permalink
Fix TextField placeholder going outside the bounds of the TextField (#…
Browse files Browse the repository at this point in the history
…567)

The problem was that we were not capping the size of the placeholder
when measuring it; but the placeholder can't be larger than the
space allocated to the actual text; setting the constraints
accordingly fixes the issue.
  • Loading branch information
rock3r authored Aug 29, 2024
1 parent c8ec545 commit a37fb3f
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,13 @@ private fun TextFieldDecorationBox(
incomingConstraints.offset(horizontal = -occupiedSpaceHorizontally).copy(minHeight = 0)
val textFieldPlaceable = measurables.single { it.layoutId == TEXT_FIELD_ID }.measure(textFieldConstraints)

// measure placeholder
val placeholderConstraints = textFieldConstraints.copy(minWidth = 0)
// measure placeholder (can't be bigger than the text)
val placeholderConstraints =
textFieldConstraints.copy(
minWidth = 0,
maxWidth = textFieldPlaceable.width,
maxHeight = textFieldPlaceable.height,
)
val placeholderPlaceable = measurables.find { it.layoutId == PLACEHOLDER_ID }?.measure(placeholderConstraints)

val width = calculateWidth(leadingPlaceable, trailingPlaceable, textFieldPlaceable, incomingConstraints)
Expand Down

0 comments on commit a37fb3f

Please sign in to comment.