11import React , { FunctionComponent , useEffect , useRef , useState } from 'react'
22import type { ChangeEvent , FocusEvent , MouseEvent } from 'react'
3- import { View , ITouchEvent } from '@tarojs/components'
3+ import { View , ITouchEvent , Input as TaroInput } from '@tarojs/components'
44import { MaskClose , Search , ArrowLeft } from '@nutui/icons-react-taro'
55import { useConfig } from '@/packages/configprovider/configprovider.taro'
66import { BasicComponent , ComponentDefaults } from '@/utils/typings'
77
88export interface SearchBarProps extends BasicComponent {
9- value ?: number | string
9+ value ?: string
1010 placeholder ?: string
1111 shape ?: 'square' | 'round'
1212 disabled ?: boolean
@@ -87,21 +87,20 @@ export const SearchBar: FunctionComponent<
8787 const searchSelf : HTMLInputElement | null = searchRef . current
8888 searchSelf && searchSelf . focus ( )
8989 }
90- const change = ( event : ChangeEvent < HTMLInputElement > ) => {
91- if ( value === event . target . value ) return
92- onChange && onChange ?.( event . target . value , event )
93- setValue ( event . target . value )
94- event . target . value === '' && forceFocus ( )
90+ const onInput = ( event : any ) => {
91+ const eventValue = event ?. detail ?. value
92+ if ( value === eventValue ) return
93+ onChange && onChange ?.( eventValue , event )
94+ setValue ( eventValue )
95+ eventValue === '' && forceFocus ( )
9596 }
96- const focus = ( event : FocusEvent < HTMLInputElement > ) => {
97- const { value } = event . target
98- onFocus && onFocus ?.( value , event )
97+ const focus = ( event : any ) => {
98+ onFocus && onFocus ( event ?. detail ?. value , event )
9999 }
100- const blur = ( event : FocusEvent < HTMLInputElement > ) => {
100+ const blur = ( event : any ) => {
101101 const searchSelf : HTMLInputElement | null = searchRef . current
102102 searchSelf && searchSelf . blur ( )
103- const { value } = event . target
104- onBlur && onBlur ?.( value , event )
103+ onBlur && onBlur ( event ?. detail ?. value , event )
105104 }
106105 useEffect ( ( ) => {
107106 setValue ( outerValue || '' )
@@ -111,26 +110,27 @@ export const SearchBar: FunctionComponent<
111110 } , [ autoFocus ] )
112111 const renderField = ( ) => {
113112 return (
114- < input
113+ < TaroInput
115114 className = { `${ classPrefix } -input ${
116115 clearable ? `${ classPrefix } -input-clear` : ''
117116 } `}
118117 ref = { searchRef }
119118 style = { style }
120119 value = { value || '' }
121120 placeholder = { placeholder || locale . placeholder }
122- disabled = { disabled }
123- readOnly = { readOnly }
124- maxLength = { maxLength }
125- onKeyPress = { onKeypress }
126- onChange = { ( e ) => change ( e ) }
127- onFocus = { ( e ) => focus ( e ) }
128- onBlur = { ( e ) => blur ( e ) }
129- onClick = { ( e ) => clickInput ( e ) }
121+ disabled = { disabled || readOnly }
122+ maxlength = { maxLength }
123+ // @ts -ignore
124+ // onKeyDown={onKeypress}
125+ onInput = { onInput }
126+ onFocus = { focus }
127+ onBlur = { blur }
128+ onClick = { clickInput }
129+ onConfirm = { onConfirm }
130130 />
131131 )
132132 }
133- const clickInput = ( e : MouseEvent < HTMLInputElement > ) => {
133+ const clickInput = ( e : any ) => {
134134 onInputClick && onInputClick ( e )
135135 }
136136 const renderLeftIn = ( ) => {
@@ -182,13 +182,16 @@ export const SearchBar: FunctionComponent<
182182 onChange && onChange ?.( '' )
183183 onClear && onClear ( event )
184184 }
185- const onKeypress = ( e : any ) => {
186- if ( e . key === 'Enter' || e . keyCode === 13 ) {
187- if ( typeof e . cancelable !== 'boolean' || e . cancelable ) {
188- e . preventDefault ( )
189- }
190- onSearch && onSearch ( value as string )
191- }
185+ // const onKeypress = (event: any) => {
186+ // if (event?.detail?.keyCode === 13) {
187+ // if (typeof event.cancelable !== 'boolean' || event.cancelable) {
188+ // event.preventDefault()
189+ // }
190+ // onSearch && onSearch(value as string)
191+ // }
192+ // }
193+ const onConfirm = ( ) => {
194+ onSearch && onSearch ( value as string )
192195 }
193196 return (
194197 < View
0 commit comments