Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tdesign-component/example/assets/api/input_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
| leftLabelStyle | TextStyle? | - | 左侧标签样式 设置该值是若出现像素溢出,请设置letterSpacing: 0 |
| maxLength | int? | 500 | 最大字数限制 |
| maxLines | int? | 1 | 最大输入行数 |
| minLines | int? | 1 | 最小输入行数 |
| needClear | bool | true | 是否需要右侧按钮变为删除 |
| obscureText | bool | false | 是否隐藏输入的文字,一般用在密码输入框中 |
| onBtnTap | GestureTapCallback? | - | 右侧按钮点击 |
Expand Down
17 changes: 17 additions & 0 deletions tdesign-component/example/assets/code/input._minLinesInput.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Widget _minLinesInput(BuildContext context) {
return TInput(
leftLabel: '备注',
controller: controller[28],
hintText: '请输入至少两行高度的内容',
maxLines: 4,
minLines: 2,
onChanged: (text) {
setState(() {});
},
onClearTap: () {
controller[28].clear();
setState(() {});
},
);
}
21 changes: 20 additions & 1 deletion tdesign-component/example/lib/page/t_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class _TInputViewPageState extends State<TInputViewPage> {
ExampleItem(
desc: '获取焦点时点击外部区域事件响应-onTapOutside', builder: _onTapOutside),
ExampleItem(
desc: '设置contentPadding内容与分割线对齐', builder: _contentPadding)
desc: '设置contentPadding内容与分割线对齐', builder: _contentPadding),
ExampleItem(desc: '设置最小输入行数', builder: _minLinesInput),
],
);
};
Expand Down Expand Up @@ -973,6 +974,24 @@ class _TInputViewPageState extends State<TInputViewPage> {
);
}

@Demo(group: 'input')
Widget _minLinesInput(BuildContext context) {
return TInput(
leftLabel: '备注',
controller: controller[28],
hintText: '请输入至少两行高度的内容',
maxLines: 4,
minLines: 2,
onChanged: (text) {
setState(() {});
},
onClearTap: () {
controller[28].clear();
setState(() {});
},
);
}

@Demo(group: 'input')
Widget _autoHeightInput(BuildContext context) {
return Column(
Expand Down
8 changes: 8 additions & 0 deletions tdesign-component/lib/src/components/input/t_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TInput extends StatelessWidget {
this.inputFormatters,
this.inputDecoration,
this.maxLines = 1,
this.minLines = 1,
this.focusNode,
this.controller,
this.cursorColor,
Expand Down Expand Up @@ -124,6 +125,9 @@ class TInput extends StatelessWidget {
/// 最大输入行数
final int? maxLines;

/// 最小输入行数
final int? minLines;

/// 获取或者取消焦点使用
final FocusNode? focusNode;

Expand Down Expand Up @@ -417,6 +421,7 @@ class TInput extends StatelessWidget {
inputFormatters: inputFormatters,
inputDecoration: inputDecoration,
maxLines: maxLines,
minLines: minLines,
maxLength: maxLength,
focusNode: focusNode,
isCollapsed: true,
Expand Down Expand Up @@ -656,6 +661,7 @@ class TInput extends StatelessWidget {
inputDecoration: inputDecoration,
isCollapsed: true,
maxLines: maxLines,
minLines: minLines,
focusNode: focusNode,
hintTextStyle: hintTextStyle ??
TextStyle(
Expand Down Expand Up @@ -783,6 +789,7 @@ class TInput extends StatelessWidget {
[LengthLimitingTextInputFormatter(maxLength)],
inputDecoration: inputDecoration,
maxLines: maxLines,
minLines: minLines,
focusNode: focusNode,
hintTextStyle: hintTextStyle ??
TextStyle(color: TTheme.of(context).textColorPlaceholder),
Expand Down Expand Up @@ -872,6 +879,7 @@ class TInput extends StatelessWidget {
inputFormatters: inputFormatters,
inputDecoration: inputDecoration,
maxLines: maxLines,
minLines: minLines,
focusNode: focusNode,
isCollapsed: true,
hintTextStyle: hintTextStyle ??
Expand Down
35 changes: 35 additions & 0 deletions tdesign-component/test/t_input_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

Widget _buildTestApp(Widget child) {
return TTheme(
data: TThemeData.defaultData(),
child: MaterialApp(
home: Scaffold(
body: child,
),
),
);
}

void main() {
group('TInput', () {
testWidgets('透传 minLines 到内部 TextField', (tester) async {
await tester.pumpWidget(
_buildTestApp(
TInput(
leftLabel: '标签文字',
hintText: '请输入文字',
maxLines: 4,
minLines: 2,
),
),
);

final textField = tester.widget<TextField>(find.byType(TextField));
expect(textField.maxLines, 4);
expect(textField.minLines, 2);
});
});
}
1 change: 1 addition & 0 deletions tdesign-site/src/input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ import 'package:tdesign_flutter/tdesign_flutter.dart';
| leftLabelStyle | TextStyle? | - | 左侧标签样式 设置该值是若出现像素溢出,请设置letterSpacing: 0 |
| maxLength | int? | 500 | 最大字数限制 |
| maxLines | int? | 1 | 最大输入行数 |
| minLines | int? | 1 | 最小输入行数 |
| needClear | bool | true | 是否需要右侧按钮变为删除 |
| obscureText | bool | false | 是否隐藏输入的文字,一般用在密码输入框中 |
| onBtnTap | GestureTapCallback? | - | 右侧按钮点击 |
Expand Down