Skip to content

Commit

Permalink
fix/max-length and max-length-enforcement on shad-input
Browse files Browse the repository at this point in the history
  • Loading branch information
nank1ro committed Nov 18, 2024
1 parent 8ab50f0 commit 6aa98fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 0.16.0

- **FEAT**: New `ShadTimePicker` and `ShadDatePickerFormField` components.

- **FIX**: `maxLength` and `maxLengthEnforcement` not working on `ShadInput`
- **CHORE**: Set minimum Flutter version to `3.24.0`
- **CHORE**: Remove `trackColor` from `ShadSwitch` (thanks to @RaghavTheGreat)

Expand Down
16 changes: 15 additions & 1 deletion lib/src/components/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,19 @@ class ShadInputState extends State<ShadInput>
);
};

final effectiveMaxLengthEnforcement = widget.maxLengthEnforcement ??
LengthLimitingTextInputFormatter.getDefaultMaxLengthEnforcement(
Theme.of(context).platform);

final effectiveInputFormatters = <TextInputFormatter>[
...?widget.inputFormatters,
if (widget.maxLength != null)
LengthLimitingTextInputFormatter(
widget.maxLength,
maxLengthEnforcement: effectiveMaxLengthEnforcement,
),
];

return ShadDisabled(
disabled: !widget.enabled,
child: _selectionGestureDetectorBuilder.buildGestureDetector(
Expand Down Expand Up @@ -512,7 +525,8 @@ class ShadInputState extends State<ShadInput>
onSubmitted: widget.onSubmitted,
onAppPrivateCommand:
widget.onAppPrivateCommand,
inputFormatters: widget.inputFormatters,
inputFormatters:
effectiveInputFormatters,
cursorWidth: widget.cursorWidth,
cursorHeight: widget.cursorHeight,
cursorRadius: widget.cursorRadius,
Expand Down

0 comments on commit 6aa98fb

Please sign in to comment.