SearchBar

SearchBar 搜索框

代码示例

import IconFont from '@/components/icon-font';
import { BfSearchBar } from '@bud-fe/react-taro-ui';
import { View } from '@tarojs/components';
import React, { useState } from 'react';
import styles from './index.module.less';
export default () => {
const [queryProps, setQueryProps] = useState({ pocName: '', pageNo: 1 });
const handleOnChange = (value) => {
console.log('handleOnChange', value);
setQueryProps({ ...queryProps, pocName: value });
};
const renderSlot = () => {
return (
<View className={styles['slot-right']}>
<IconFont type="icon-wodeshenpi" style={{ marginRight: 4 }} />
我的审批
</View>
);
};
return (
<>
<View className="group-title">基础用法</View>
<BfSearchBar placeholder="请输入售点名称/售点地址" onChange={handleOnChange} value={queryProps.pocName} />
<View className="group-title">带搜索按钮</View>
<BfSearchBar
placeholder="请输入售点名称/售点地址"
searchBtn
onSearch={(val) => {
console.log('onSearch', val);
}}
/>
<View className="group-title">禁用防抖</View>
<BfSearchBar
placeholder="请输入售点名称/售点地址"
onChange={(value) => {
console.log('handleOnChange', value);
}}
disableDebounce
/>
<View className="group-title">rightSlot </View>
<BfSearchBar placeholder="请输入审批名称" rightSlot={renderSlot()} />
<BfSearchBar placeholder="请输入审批名称" rightSlot={<View style={{ color: 'red' }}>custom</View>} />
</>
);
};

API

属性名描述类型默认值
searchBtn是否显示搜索按钮。默认 false,即输入后自动触发搜索booleanfalse
onSearch点击搜索按钮时触发。仅 searchBtn 为 true 时有效(val: string) => void--
rightSlot右插槽any--
disableDebounce禁用防抖功能booleanfalse
debounceTime防抖时间number500
customDisabledClass自定义内部 input disabled 状态的 className NOTE:小程序的 input 组件为 disabled 时无法修改样式string--
onChange输入改变的回调,默认 500ms 的防抖(value: string) => void--
enableNative支付宝/钉钉小程序专属propsbooleanfalse
dumi10:24