Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(textarea): add label slot #348

Merged
merged 1 commit into from
Apr 14, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/textarea/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ autosize | Boolean | false | 是否自动增高,值为 autosize 时,style.he
confirm-hold | Boolean | false | 点击键盘右下角按钮时是否保持键盘不收起点 | N
confirm-type | String | done | 设置键盘右下角按钮的文字,仅在 type='text'时生效。可选项:send/search/next/go/done。TS 类型:`'send' | 'search' | 'next' | 'go' | 'done'` | N
disabled | Boolean | false | 是否禁用文本框 | N
external-classes | Array | - | 组件类名,分别用于表示组件外层元素、输入框、占位符、标签名等元素类名。`['t-class', 't-class-textarea', 't-class-placeholder', 't-class-name']` | N
external-classes | Array | - | 组件类名,分别用于表示组件外层元素、输入框、占位符、标签名等元素类名。`['t-class', 't-class-textarea', 't-class-placeholder', 't-class-label']` | N
focus | Boolean | false | 自动聚焦 | N
label | String / Slot | - | 左侧文本 | N
maxcharacter | Number | - | 用户最多可以输入的字符个数,一个中文汉字表示两个字符长度 | N
Expand Down
2 changes: 1 addition & 1 deletion src/textarea/textarea.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
position: relative;
background-color: #fff;

&__name {
&__name:not(:empty) {
position: relative;
padding: @textarea-vertical-padding @textarea-horizontal-padding;
font-size: @textarea-font-size;
Expand Down
8 changes: 7 additions & 1 deletion src/textarea/textarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ export default class Textarea extends SuperComponent {

behaviors = ['wx://form-field'];

externalClasses = ['t-class', 't-class-textarea', 't-class-placeholder', 't-class-name'];
externalClasses = [
`${prefix}-class`,
`${prefix}-class-textarea`,
`${prefix}-class-placeholder`,
`${prefix}-class-label`,
];

properties = props;

data = {
prefix,
inputValue: '',
classPrefix: name,
characterLength: 0,
Expand Down
11 changes: 6 additions & 5 deletions src/textarea/textarea.wxml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<view class="{{classPrefix}} t-class">
<view wx:if="{{ label && label.length > 0 }}" class="{{classPrefix}}__name t-class-name">
<view>{{ label }}</view>
<view class="{{classPrefix}} {{prefix}}-class">
<view class="{{classPrefix}}__name {{prefix}}-class-label">
<view wx:if="{{ label && label.length > 0 }}">{{ label }}</view>
<slot wx:else name="label" />
</view>
<view class="{{classPrefix}}__wrapper">
<textarea
maxlength="{{maxlength || -1}}"
disabled="{{disabled}}"
placeholder="{{placeholder}}"
class="{{classPrefix}}__wrapper-textarea t-class-textarea"
placeholder-class="{{classPrefix}}__placeholder t-class-placeholder"
class="{{classPrefix}}__wrapper-textarea {{prefix}}-class-textarea"
placeholder-class="{{classPrefix}}__placeholder {{prefix}}-class-placeholder"
model:value="{{value}}"
auto-focus="{{autofocus}}"
focus="{{focus}}"
Expand Down