Skip to content

Commit

Permalink
feat(field): expand click area support (#5479)
Browse files Browse the repository at this point in the history
  • Loading branch information
landluck authored Jul 10, 2023
1 parent f26de0c commit f197c5f
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 41 deletions.
24 changes: 16 additions & 8 deletions packages/cascader/test/__snapshots__/demo.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
地区
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
Expand All @@ -60,6 +61,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{true}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请选择地区"
Expand Down Expand Up @@ -138,14 +140,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
地区
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
Expand All @@ -169,6 +172,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{true}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请选择地区"
Expand Down Expand Up @@ -247,14 +251,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
地区
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
Expand All @@ -278,6 +283,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{true}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请选择地区"
Expand Down Expand Up @@ -356,14 +362,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
地区
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
Expand All @@ -387,6 +394,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{true}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请选择地区"
Expand Down
24 changes: 16 additions & 8 deletions packages/config-provider/test/__snapshots__/demo.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
评分
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
Expand Down Expand Up @@ -167,6 +168,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder=""
Expand Down Expand Up @@ -210,14 +212,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
滑块
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
Expand Down Expand Up @@ -282,6 +285,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder=""
Expand Down Expand Up @@ -386,14 +390,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
评分
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
Expand Down Expand Up @@ -523,6 +528,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder=""
Expand Down Expand Up @@ -566,14 +572,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
滑块
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
Expand Down Expand Up @@ -638,6 +645,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder=""
Expand Down
6 changes: 5 additions & 1 deletion packages/field/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,17 @@ Page({

相关的讨论可以查看[微信开放社区](https://developers.weixin.qq.com/community/search?query=input%20%E6%89%8B%E5%86%99%E8%BE%93%E5%85%A5&page=1&block=1&random=1567079239098)

### 如何扩大点击区域?点击 label、错误信息 都能聚焦唤起键盘呢?

升级至 1.10.21 版本及以上,配置 `name` 属性即可

## API

### Props

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| name | 在表单内提交时的标识符 | _string_ | - |
| name | 在表单内提交时的标识符。可以通过配置 `name` 来扩大点击区域 | _string_ | - |
| label | 输入框左侧文本 | _string_ | - |
| size | 单元格大小,可选值为 `large` | _string_ | - |
| value | 当前输入的值 | _string \| number_ | - |
Expand Down
12 changes: 6 additions & 6 deletions packages/field/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
custom-class="custom-class van-field"
>
<slot name="left-icon" slot="icon" />
<view wx:if="{{ label }}" class="label-class {{ utils.bem('field__label', { disabled }) }}" slot="title">
<label for="{{ name }}" wx:if="{{ label }}" class="label-class {{ utils.bem('field__label', { disabled }) }}" slot="title">
{{ label }}
</view>
</label>
<slot wx:else name="label" slot="title" />
<view class="{{ utils.bem('field__body', [type]) }}">
<view class="{{ utils.bem('field__control', [inputAlign, 'custom']) }}" bindtap="onClickInput">
Expand Down Expand Up @@ -47,10 +47,10 @@
<slot name="button" />
</view>
</view>
<view wx:if="{{ showWordLimit && maxlength }}" class="van-field__word-limit">
<label for="{{ name }}" wx:if="{{ showWordLimit && maxlength }}" class="van-field__word-limit">
<view class="{{ utils.bem('field__word-num', { full: value.length >= maxlength }) }}">{{ value.length >= maxlength ? maxlength : value.length }}</view>/{{ maxlength }}
</view>
<view wx:if="{{ errorMessage }}" class="{{ utils.bem('field__error-message', [errorMessageAlign, { disabled, error }]) }}">
</label>
<label for="{{ name }}" wx:if="{{ errorMessage }}" class="{{ utils.bem('field__error-message', [errorMessageAlign, { disabled, error }]) }}">
{{ errorMessage }}
</view>
</label>
</van-cell>
1 change: 1 addition & 0 deletions packages/field/input.wxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<input
id="{{ name }}"
class="{{ utils.bem('field__control', [inputAlign, { disabled, error }]) }} input-class"
type="{{ type }}"
focus="{{ focus }}"
Expand Down
Loading

0 comments on commit f197c5f

Please sign in to comment.