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><BfSearchBarplaceholder="请输入售点名称/售点地址"searchBtnonSearch={(val) => {console.log('onSearch', val);}}/><View className="group-title">禁用防抖</View><BfSearchBarplaceholder="请输入售点名称/售点地址"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,即输入后自动触发搜索 | boolean | false |
onSearch | 点击搜索按钮时触发。仅 searchBtn 为 true 时有效 | (val: string) => void | -- |
rightSlot | 右插槽 | any | -- |
disableDebounce | 禁用防抖功能 | boolean | false |
debounceTime | 防抖时间 | number | 500 |
customDisabledClass | 自定义内部 input disabled 状态的 className NOTE:小程序的 input 组件为 disabled 时无法修改样式 | string | -- |
onChange | 输入改变的回调,默认 500ms 的防抖 | (value: string) => void | -- |
enableNative | 支付宝/钉钉小程序专属props | boolean | false |