Skip to content

Commit 9dff0fd

Browse files
zhc5253499657insummer
authored andcommitted
fix/input
修复自定义事件层级 新增hideLabel属性,可隐藏左侧label 小程序中新增input隐藏label示例
1 parent e459b19 commit 9dff0fd

File tree

10 files changed

+65
-31
lines changed

10 files changed

+65
-31
lines changed

dist/input/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Component({
1616
type: String,
1717
value: ''
1818
},
19+
// 是否隐藏label
20+
hideLabel:{
21+
type: Boolean,
22+
value: false
23+
},
1924
// 是否自定义label部分
2025
labelCustom: {
2126
type: Boolean,
@@ -119,18 +124,18 @@ Component({
119124
value
120125
});
121126

122-
this.triggerEvent('linchange', event);
127+
this.triggerEvent('linchange', event.detail);
123128
},
124129

125130
handleInputFocus(event) {
126-
this.triggerEvent('linfocus', event);
131+
this.triggerEvent('linfocus', event.detail);
127132
},
128133

129134
handleInputBlur(event) {
130135
this.validatorData({
131136
value: event.detail.value
132137
});
133-
this.triggerEvent('linblur', event);
138+
this.triggerEvent('linblur', event.detail);
134139
},
135140
handleInputConfirm(event) {
136141
const {
@@ -144,13 +149,13 @@ Component({
144149
value
145150
});
146151

147-
this.triggerEvent('linconfirm', event);
152+
this.triggerEvent('linconfirm', event.detail);
148153
},
149154
onClearTap(event) {
150155
this.setData({
151156
value: ''
152157
})
153-
this.triggerEvent('linclear', event);
158+
this.triggerEvent('linclear', event.detail);
154159
},
155160
}
156161
})

dist/input/index.wxml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
style="width:{{width}}rpx">
55
<view class='mask' wx:if="{{disabled}}"></view>
66
<view class='row' hidden="{{ showRow ? '' : 'hidden' }}" style="width:{{width}}rpx;"></view>
7-
<view wx:if="{{label && !labelCustom}}" class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
7+
<view wx:if="{{label && !labelCustom}}" hidden="{{hideLabel}}" class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
88
<text><text class='text-require' wx:if="{{required}}">* </text>{{label}}<text wx:if="{{colon}}">:</text>
99
</text>
1010
</view>
11-
<view wx:else class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
11+
<view wx:else hidden="{{hideLabel}}" class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
1212
<slot name="left" />
1313
</view>
1414
<!-- 小程序表单组件 -->
1515
<input
16-
class="input"
16+
class="input {{hideLabel?'hideLabel':''}}"
1717
value="{{ value }}"
1818
type="{{type}}"
1919
password="{{type==='password'}}"

dist/input/index.wxss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.form-item{position:relative;font-size:28rpx;color:#333;width:750rpx;height:88rpx;display:flex;flex-direction:row;align-items:center;padding-right:25rpx;box-sizing:border-box}.row{position:absolute;bottom:0;right:0;height:2rpx;width:730rpx;background:#f3f3f3}.text-require{color:#e23;vertical-align:middle}.form-label{display:flex;flex-direction:row;align-items:center;height:88rpx;padding-left:25rpx;padding-right:15rpx;box-sizing:border-box}.disabled{color:#9a9a9a!important}.mask{position:absolute;z-index:999;height:100%;width:100%}.form-label-right{justify-content:flex-end}.form-label-left{justify-content:flex-start}.input{height:100%;line-height:100%;flex:1}.close{height:36rpx;width:36rpx;background:#ddd;display:flex;flex-direction:row;align-items:center;justify-content:center;border-radius:50%;margin-right:20rpx}.pls-class{color:#9a9a9a}
1+
.form-item{position:relative;font-size:28rpx;color:#333;width:750rpx;height:88rpx;display:flex;flex-direction:row;align-items:center;padding-right:25rpx;box-sizing:border-box}.row{position:absolute;bottom:0;right:0;height:2rpx;width:730rpx;background:#f3f3f3}.text-require{color:#e23;vertical-align:middle}.form-label{display:flex;flex-direction:row;align-items:center;height:88rpx;padding-left:25rpx;padding-right:15rpx;box-sizing:border-box}.disabled{color:#9a9a9a!important}.mask{position:absolute;z-index:999;height:100%;width:100%}.form-label-right{justify-content:flex-end}.form-label-left{justify-content:flex-start}.input{height:100%;line-height:100%;flex:1}.close{height:36rpx;width:36rpx;background:#ddd;display:flex;flex-direction:row;align-items:center;justify-content:center;border-radius:50%;margin-right:20rpx}.pls-class{color:#9a9a9a}.hideLabel{padding-left:25rpx}

examples/dist/input/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Component({
1616
type: String,
1717
value: ''
1818
},
19+
// 是否隐藏label
20+
hideLabel:{
21+
type: Boolean,
22+
value: false
23+
},
1924
// 是否自定义label部分
2025
labelCustom: {
2126
type: Boolean,
@@ -119,18 +124,18 @@ Component({
119124
value
120125
});
121126

122-
this.triggerEvent('linchange', event);
127+
this.triggerEvent('linchange', event.detail);
123128
},
124129

125130
handleInputFocus(event) {
126-
this.triggerEvent('linfocus', event);
131+
this.triggerEvent('linfocus', event.detail);
127132
},
128133

129134
handleInputBlur(event) {
130135
this.validatorData({
131136
value: event.detail.value
132137
});
133-
this.triggerEvent('linblur', event);
138+
this.triggerEvent('linblur', event.detail);
134139
},
135140
handleInputConfirm(event) {
136141
const {
@@ -144,13 +149,13 @@ Component({
144149
value
145150
});
146151

147-
this.triggerEvent('linconfirm', event);
152+
this.triggerEvent('linconfirm', event.detail);
148153
},
149154
onClearTap(event) {
150155
this.setData({
151156
value: ''
152157
})
153-
this.triggerEvent('linclear', event);
158+
this.triggerEvent('linclear', event.detail);
154159
},
155160
}
156161
})

examples/dist/input/index.wxml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
style="width:{{width}}rpx">
55
<view class='mask' wx:if="{{disabled}}"></view>
66
<view class='row' hidden="{{ showRow ? '' : 'hidden' }}" style="width:{{width}}rpx;"></view>
7-
<view wx:if="{{label && !labelCustom}}" class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
7+
<view wx:if="{{label && !labelCustom}}" hidden="{{hideLabel}}" class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
88
<text><text class='text-require' wx:if="{{required}}">* </text>{{label}}<text wx:if="{{colon}}">:</text>
99
</text>
1010
</view>
11-
<view wx:else class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
11+
<view wx:else hidden="{{hideLabel}}" class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
1212
<slot name="left" />
1313
</view>
1414
<!-- 小程序表单组件 -->
1515
<input
16-
class="input"
16+
class="input {{hideLabel?'hideLabel':''}}"
1717
value="{{ value }}"
1818
type="{{type}}"
1919
password="{{type==='password'}}"

examples/dist/input/index.wxss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.form-item{position:relative;font-size:28rpx;color:#333;width:750rpx;height:88rpx;display:flex;flex-direction:row;align-items:center;padding-right:25rpx;box-sizing:border-box}.row{position:absolute;bottom:0;right:0;height:2rpx;width:730rpx;background:#f3f3f3}.text-require{color:#e23;vertical-align:middle}.form-label{display:flex;flex-direction:row;align-items:center;height:88rpx;padding-left:25rpx;padding-right:15rpx;box-sizing:border-box}.disabled{color:#9a9a9a!important}.mask{position:absolute;z-index:999;height:100%;width:100%}.form-label-right{justify-content:flex-end}.form-label-left{justify-content:flex-start}.input{height:100%;line-height:100%;flex:1}.close{height:36rpx;width:36rpx;background:#ddd;display:flex;flex-direction:row;align-items:center;justify-content:center;border-radius:50%;margin-right:20rpx}.pls-class{color:#9a9a9a}
1+
.form-item{position:relative;font-size:28rpx;color:#333;width:750rpx;height:88rpx;display:flex;flex-direction:row;align-items:center;padding-right:25rpx;box-sizing:border-box}.row{position:absolute;bottom:0;right:0;height:2rpx;width:730rpx;background:#f3f3f3}.text-require{color:#e23;vertical-align:middle}.form-label{display:flex;flex-direction:row;align-items:center;height:88rpx;padding-left:25rpx;padding-right:15rpx;box-sizing:border-box}.disabled{color:#9a9a9a!important}.mask{position:absolute;z-index:999;height:100%;width:100%}.form-label-right{justify-content:flex-end}.form-label-left{justify-content:flex-start}.input{height:100%;line-height:100%;flex:1}.close{height:36rpx;width:36rpx;background:#ddd;display:flex;flex-direction:row;align-items:center;justify-content:center;border-radius:50%;margin-right:20rpx}.pls-class{color:#9a9a9a}.hideLabel{padding-left:25rpx}

examples/pages/components/form/pages/input/index.wxml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@
9595
</view>
9696
</content-card>
9797

98+
<content-card
99+
class="content"
100+
name="隐藏左侧label"
101+
>
102+
<view class='buttun-wrapper'>
103+
<l-input
104+
label="标题"
105+
placeholder="这里没有隐藏标题"
106+
label-width="170"/>
107+
<l-input
108+
label="清除按钮"
109+
clear="{{true}}"
110+
label-width="170"
111+
hideLabel="{{true}}"
112+
placeholder="这里隐藏了标题" />
113+
</view>
114+
</content-card>
115+
98116
<content-card
99117
class="content"
100118
name="经典案例"

src/input/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Component({
1616
type: String,
1717
value: ''
1818
},
19+
// 是否隐藏label
20+
hideLabel:{
21+
type: Boolean,
22+
value: false
23+
},
1924
// 是否自定义label部分
2025
labelCustom: {
2126
type: Boolean,
@@ -119,18 +124,18 @@ Component({
119124
value
120125
});
121126

122-
this.triggerEvent('linchange', event);
127+
this.triggerEvent('linchange', event.detail);
123128
},
124129

125130
handleInputFocus(event) {
126-
this.triggerEvent('linfocus', event);
131+
this.triggerEvent('linfocus', event.detail);
127132
},
128133

129134
handleInputBlur(event) {
130135
this.validatorData({
131136
value: event.detail.value
132137
});
133-
this.triggerEvent('linblur', event);
138+
this.triggerEvent('linblur', event.detail);
134139
},
135140
handleInputConfirm(event) {
136141
const {
@@ -144,13 +149,13 @@ Component({
144149
value
145150
});
146151

147-
this.triggerEvent('linconfirm', event);
152+
this.triggerEvent('linconfirm', event.detail);
148153
},
149154
onClearTap(event) {
150155
this.setData({
151156
value: ''
152157
})
153-
this.triggerEvent('linclear', event);
158+
this.triggerEvent('linclear', event.detail);
154159
},
155160
}
156161
})

src/input/index.less

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* input/input.wxss */
22

3-
43
.form-item{
54
position: relative;
65
font-size: 28rpx;
@@ -51,10 +50,10 @@
5150
}
5251

5352
/* labelLayout */
54-
.form-item-top{
53+
// .form-item-top{
5554
// display: flex;
5655
// flex-direction: column;
57-
}
56+
// }
5857

5958
// .form-item-left{
6059
// display: flex;
@@ -77,7 +76,6 @@
7776
justify-content: flex-start
7877
}
7978

80-
8179
.input{
8280
height: 100%;
8381
line-height: 100%;
@@ -96,7 +94,10 @@
9694
margin-right: 20rpx;
9795
}
9896

99-
10097
.pls-class{
10198
color: #9a9a9a
99+
}
100+
101+
.hideLabel{
102+
padding-left: 25rpx;
102103
}

src/input/index.wxml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
style="width:{{width}}rpx">
55
<view class='mask' wx:if="{{disabled}}"></view>
66
<view class='row' hidden="{{ showRow ? '' : 'hidden' }}" style="width:{{width}}rpx;"></view>
7-
<view wx:if="{{label && !labelCustom}}" class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
7+
<view wx:if="{{label && !labelCustom}}" hidden="{{hideLabel}}" class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
88
<text><text class='text-require' wx:if="{{required}}">* </text>{{label}}<text wx:if="{{colon}}">:</text>
99
</text>
1010
</view>
11-
<view wx:else class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
11+
<view wx:else hidden="{{hideLabel}}" class='form-label l-label-class form-label-{{labelLayout}}' style='{{labelLayout !== "top" ? "width:"+ labelWidth+ "rpx;" : "" }} height:{{labelLayout== "top" ? labelWidth + "rpx" : "" }}'>
1212
<slot name="left" />
1313
</view>
1414
<!-- 小程序表单组件 -->
1515
<input
16-
class="input"
16+
class="input {{hideLabel?'hideLabel':''}}"
1717
value="{{ value }}"
1818
type="{{type}}"
1919
password="{{type==='password'}}"

0 commit comments

Comments
 (0)