Skip to content

Commit

Permalink
fix: [MDS-1003] Fix TextInput overflow issues (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kypsis committed Feb 19, 2024
1 parent fb59d5b commit 058042c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 51 deletions.
9 changes: 5 additions & 4 deletions example/lib/src/storybook/stories/text_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class TextAreaStory extends StatelessWidget {
initial: true,
);

final growableKnob = context.knobs.boolean(
label: "Growable",
description: "Whether MoonTextArea is growable with unfixed height",
final expandsKnob = context.knobs.boolean(
label: "expands",
description: "Whether MoonTextArea can expand to fit its contents.",
);

final showHelperKnob = context.knobs.boolean(
Expand All @@ -111,7 +111,8 @@ class TextAreaStory extends StatelessWidget {
children: [
MoonTextArea(
enabled: enabledKnob,
height: growableKnob ? null : 200,
expands: expandsKnob,
height: expandsKnob ? null : 200,
textColor: textColor,
hintTextColor: hintTextColor,
backgroundColor: backgroundColor,
Expand Down
10 changes: 8 additions & 2 deletions lib/src/widgets/common/border_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:moon_design/moon_design.dart';

class BorderContainer extends StatefulWidget {
final bool expands;
final Clip clipBehavior;
final Color? backgroundColor;
final Decoration? decoration;
Expand All @@ -17,6 +18,7 @@ class BorderContainer extends StatefulWidget {
/// Primarily utilized in [MoonTextInput] and [MoonTextInputGroup].
const BorderContainer({
super.key,
this.expands = false,
this.clipBehavior = Clip.none,
this.backgroundColor,
this.decoration,
Expand Down Expand Up @@ -84,8 +86,12 @@ class _BorderContainerState extends State<BorderContainer> with SingleTickerProv
animation: _borderAnimation,
builder: (context, child) {
return Container(
height: widget.height,
width: widget.width,
constraints: BoxConstraints(
minHeight: widget.height ?? 0,
minWidth: widget.width ?? 0,
maxHeight: widget.expands ? double.infinity : widget.height ?? double.infinity,
maxWidth: widget.expands ? double.infinity : widget.width ?? double.infinity,
),
clipBehavior: widget.clipBehavior,
decoration: widget.decoration ??
ShapeDecorationWithPremultipliedAlpha(
Expand Down
6 changes: 5 additions & 1 deletion lib/src/widgets/text_area/text_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class MoonTextArea extends StatelessWidget {
/// {@macro flutter.services.TextInputConfiguration.enableSuggestions}
final bool enableSuggestions;

/// {@macro flutter.widgets.editableText.expands}
final bool expands;

/// {@macro flutter.widgets.editableText.readOnly}
final bool readOnly;

Expand Down Expand Up @@ -224,6 +227,7 @@ class MoonTextArea extends StatelessWidget {
this.enableIMEPersonalizedLearning = true,
this.enableInteractiveSelection,
this.enableSuggestions = true,
this.expands = false,
this.readOnly = false,
this.scribbleEnabled = true,
this.showCursor,
Expand Down Expand Up @@ -343,7 +347,7 @@ class MoonTextArea extends StatelessWidget {
enableSuggestions: enableSuggestions,
errorColor: effectiveErrorColor,
errorBuilder: errorBuilder,
expands: height != null,
expands: expands,
focusNode: focusNode,
height: height,
helper: helper,
Expand Down
81 changes: 37 additions & 44 deletions lib/src/widgets/text_input/text_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1298,21 +1298,21 @@ class _MoonTextInputState extends State<MoonTextInput>
backgroundColor: effectiveBackgroundColor,
border: resolvedBorder,
decoration: widget.decoration,
height: widget.keyboardType == TextInputType.multiline && widget.height == null ? null : effectiveHeight,
expands: widget.expands,
width: widget.width,
height: effectiveHeight,
duration: effectiveTransitionDuration,
curve: effectiveTransitionCurve,
child: Row(
crossAxisAlignment: widget.expands ? CrossAxisAlignment.center : CrossAxisAlignment.stretch,
children: [
if (widget.leading != null)
SizedBox(
height: double.infinity,
child: Padding(
padding: EdgeInsetsDirectional.only(
start: resolvedContentPadding.left,
end: effectiveGap,
),
child: widget.leading,
Padding(
padding: EdgeInsetsDirectional.only(
start: resolvedContentPadding.left,
end: effectiveGap,
),
child: widget.leading,
),
Expanded(
child: Padding(
Expand Down Expand Up @@ -1371,15 +1371,12 @@ class _MoonTextInputState extends State<MoonTextInput>
),
),
if (widget.trailing != null)
SizedBox(
height: double.infinity,
child: Padding(
padding: EdgeInsetsDirectional.only(
start: effectiveGap,
end: resolvedContentPadding.right,
),
child: widget.trailing,
Padding(
padding: EdgeInsetsDirectional.only(
start: effectiveGap,
end: resolvedContentPadding.right,
),
child: widget.trailing,
),
],
),
Expand All @@ -1392,38 +1389,34 @@ class _MoonTextInputState extends State<MoonTextInput>
opacity: widget.enabled ? 1.0 : effectiveDisabledOpacityValue,
curve: effectiveTransitionCurve,
duration: effectiveTransitionDuration,
child: SizedBox(
width: widget.width,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
child,
if (widget.helper != null || (widget.errorText != null))
RepaintBoundary(
child: IconTheme(
data: IconThemeData(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
child,
if (widget.helper != null || (widget.errorText != null))
RepaintBoundary(
child: IconTheme(
data: IconThemeData(
color: widget.errorText != null ? effectiveErrorColor : effectiveHintTextColor,
),
child: DefaultTextStyle(
style: effectiveHelperTextStyle.copyWith(
color: widget.errorText != null ? effectiveErrorColor : effectiveHintTextColor,
),
child: DefaultTextStyle(
style: effectiveHelperTextStyle.copyWith(
color: widget.errorText != null ? effectiveErrorColor : effectiveHintTextColor,
),
child: widget.errorText != null
? widget.errorBuilder?.call(context, widget.errorText) ??
Padding(
padding: effectiveHelperPadding,
child: MoonErrorMessage(errorText: widget.errorText!),
)
: Padding(
child: widget.errorText != null
? widget.errorBuilder?.call(context, widget.errorText) ??
Padding(
padding: effectiveHelperPadding,
child: widget.helper,
),
),
child: MoonErrorMessage(errorText: widget.errorText!),
)
: Padding(
padding: effectiveHelperPadding,
child: widget.helper,
),
),
),
],
),
),
],
),
);

Expand Down

0 comments on commit 058042c

Please sign in to comment.