Skip to content

Commit 171ae97

Browse files
committed
Merge remote-tracking branch 'zaihui/dev' into try-monorepo
2 parents cf1f398 + 1fb076f commit 171ae97

File tree

5 files changed

+63
-14
lines changed

5 files changed

+63
-14
lines changed

packages/demo/src/pages/Input/Input.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ const InputPage: React.FC = () => {
2828
placeholder='请输入身份证号码'
2929
/>
3030
<HuiInput label='兑换人民币' placeholder='请输入金额' unit='元' />
31-
<HuiInput placeholder='无标题输入框样式' divider={false} />
31+
<HuiInput placeholder='无标题输入框样式' divider={false} arrow />
32+
<HuiInput
33+
label='可清除'
34+
placeholder='请输入'
35+
divider={false}
36+
clearable
37+
unit='元'
38+
/>
3239
</GroupSection>
3340
<GroupSection title='可以调整文本对齐方式'>
3441
<HuiInput

packages/weapp-components/src/components/Button/Button.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ const HuiButton: React.FC<HuiButtonProps> = (props) => {
9090
...style,
9191
}
9292

93-
const handleClick = (e: ITouchEvent) => {
94-
if (!disabled && onClick) {
95-
onClick(e)
96-
}
97-
}
98-
9993
const iconSizeMap = {
10094
small: 13,
10195
medium: 14,
@@ -104,6 +98,12 @@ const HuiButton: React.FC<HuiButtonProps> = (props) => {
10498

10599
const buttonDisabled = disabled || loading
106100

101+
const handleClick = (e: ITouchEvent) => {
102+
if (!buttonDisabled && onClick) {
103+
onClick(e)
104+
}
105+
}
106+
107107
const buttonContent = (
108108
<Block>
109109
{prefixIcon && (

packages/weapp-components/src/components/Input/Input.tsx

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-empty-function */
2-
import React from 'react'
2+
import React, { useEffect, useMemo, useState } from 'react'
33
import cx from 'classnames'
44
import { View, Input } from '@tarojs/components'
55
import {
@@ -24,6 +24,8 @@ export interface HuiInputProps extends ViewProps {
2424
placeholder?: string
2525
/** 右侧箭头 */
2626
arrow?: boolean
27+
/** 清除按钮 */
28+
clearable?: boolean
2729
// withArray?: boolean
2830
/** 报错信息 */
2931
errorMsg?: React.ReactNode
@@ -48,6 +50,8 @@ export interface HuiInputProps extends ViewProps {
4850
className?: string
4951
/** 点击事件 */
5052
onClick?: (event: ITouchEvent) => void
53+
/** 清除事件 */
54+
onClear?: CommonEventFunction<InputProps.inputForceEventDetail>
5155
/** onInput事件 */
5256
onInput?: CommonEventFunction<InputProps.inputEventDetail>
5357
/** 输入框失获取焦点时触发 */
@@ -74,11 +78,24 @@ const HuiInput: React.FC<HuiInputProps> = (props) => {
7478
className = '',
7579
style,
7680
onClick,
81+
onInput = () => {},
7782
align = 'left',
7883
required = true,
7984
labelIcon,
85+
clearable,
8086
} = props
8187

88+
const [innerValue, setInnerValue] = useState(value)
89+
90+
useEffect(() => {
91+
setInnerValue(value)
92+
}, [value])
93+
94+
const mergedOnInput = (e) => {
95+
setInnerValue(e.detail.value)
96+
onInput(e)
97+
}
98+
8299
const labelDom = label ? (
83100
<View className='label'>
84101
<View>{label}</View>
@@ -100,15 +117,15 @@ const HuiInput: React.FC<HuiInputProps> = (props) => {
100117
<View
101118
className={cx(
102119
'display-area',
103-
{ 'none-value': !value },
120+
{ 'none-value': !innerValue },
104121
{ 'right-align': label && align === 'right' },
105122
)}
106123
>
107-
{value || placeholder}
124+
{innerValue || placeholder}
108125
</View>
109126
) : (
110127
<Input
111-
value={value}
128+
value={innerValue}
112129
className={cx('input', { 'right-align': label && align === 'right' })}
113130
type={type}
114131
placeholder={placeholder}
@@ -118,7 +135,7 @@ const HuiInput: React.FC<HuiInputProps> = (props) => {
118135
adjustPosition={props.adjustPosition}
119136
confirmType={props.confirmType || 'done'}
120137
maxlength={props.maxLength || 140}
121-
onInput={props.onInput || (() => {})}
138+
onInput={mergedOnInput}
122139
onBlur={props.onBlur || (() => {})}
123140
onFocus={props.onFocus || (() => {})}
124141
onConfirm={props.onConfirm || (() => {})}
@@ -136,6 +153,30 @@ const HuiInput: React.FC<HuiInputProps> = (props) => {
136153
/>
137154
) : null
138155

156+
const showClear = useMemo(
157+
() => clearable && !!innerValue,
158+
[clearable, innerValue],
159+
)
160+
161+
// input右侧清除按钮是否展示
162+
const inputClearDom = showClear ? (
163+
<View
164+
style={{ marginLeft: '10px' }}
165+
onClick={(e) => {
166+
e.preventDefault()
167+
mergedOnInput({ detail: { value: '' } })
168+
props.onClear?.(e)
169+
}}
170+
>
171+
<HuiIcon
172+
name='005-close2'
173+
style={{
174+
color: '#c5c5c5',
175+
}}
176+
/>
177+
</View>
178+
) : null
179+
139180
// 分割线是否展示 & 分割线颜色
140181
const divideLineDom =
141182
errorMsg || divider ? (
@@ -169,6 +210,7 @@ const HuiInput: React.FC<HuiInputProps> = (props) => {
169210
{labelDom}
170211
<View className='input-content'>
171212
{inputDom}
213+
{inputClearDom}
172214
{props.unit ? <View className='unit'>{props.unit}</View> : null}
173215
</View>
174216
{inputArrayDom}

packages/weapp-components/src/components/Tabs/Tabs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const HuiTabs: React.FC<HuiTabsProps> = (props) => {
118118
temp.push(res)
119119
}
120120
}
121-
const res = await selectorQueryClientRect(`#${tabsRef.current.uid}`)
121+
const res = await selectorQueryClientRect(`#${tabsRef?.current?.uid}`)
122122
setTabsInfos(temp)
123123
setTabsWidth(res?.width)
124124
})

packages/weapp-components/src/components/Tag/Tag.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const HuiTag: React.FC<HuiTagProps> = (props) => {
3535

3636
const getTagBackground = () => {
3737
if (type === 'semitransparent') {
38-
return addOpacityToHexColor(color, 0.2)
38+
return addOpacityToHexColor(color, 0.1)
3939
} else if (type === 'solid') {
4040
return color
4141
}

0 commit comments

Comments
 (0)