2.0.33 • Published 3 years ago

bee-select v2.0.33

Weekly downloads
291
License
MIT
Repository
github
Last release
3 years ago

bee-select

npm version Build Status Coverage Status dependencies Status NPM downloads Average time to resolve an issue Percentage of issues still open

下拉弹出菜单,代替原生的选择器。当然Select扩展了其他功能:多选,级联,搜索过滤单选和搜索过滤多选与自动填充选择。

使用

使用单独的bee-select包

组件引入

先进行下载bee-select包

npm install --save bee-select

组件调用

import Select from 'bee-select';
const Option = Select.Option;

React.render(<div>
class Demo extends Component {
	handleChange(value) {
  		console.log(`selected ${value}`);
	}
	render(){
		return( 
			<div>
			    <Select defaultValue="lucy" style={{ width: 200 }} onChange={handleChange}>
			      <Option value="jack">Jack</Option>
			      <Option value="lucy">Lucy</Option>
			      <Option value="disabled" disabled>Disabled</Option>
			      <Option value="yiminghe">Yiminghe</Option>
			    </Select>
			</div>
		)
	}
}
</div>, document.getElementById('target1');

样式引入

//如果例子中引入其他组件,需将此组件样式引入

  • 可以使用link引入dist目录下bee-select.css
<link rel="stylesheet" href="./node_modules/build/bee-select.css">
  • 可以在js中import样式
import "./node_modules/src/Select.scss"
//或是
import "./node_modules/build/bee-select.css"

API

Select

参数说明类型默认值
open控制下拉框展开收起boolfalse
value指定当前选中的条目string/array/react node-
defaultValue指定默认选中的条目string/array/react node-
multiple支持多选boolfalse
allowClear支持清除, 单选模式有效boolfalse
filterOption是否根据输入项进行筛选。当其为一个函数时,会接收 inputValue option 两个参数,当 option 符合筛选条件时,应返回 true,反之则返回 falsebool/functrue
tags可以把随意输入的条目作为 tag,输入项不需要与下拉选项匹配boolfalse
onSelect被选中时调用,参数为选中项的 value 值func-
onDeselect取消选中时调用,参数为选中项的 option value 值,仅在 multiple 或 tags 模式下生效func-
onChange选中 option,或 input 的 value 变化(combobox 模式下)时,调用此函数bool-
scrollToEdn钩子函数 下拉列表的滚动条滚到最底触发func-
onSearch文本框值变化时回调func-
onBlur失去焦点的时回调func返回当前值array
onFocus获得焦点时回调func返回当前值array
placeholder选择框默认文字string-
notFoundContent当下拉列表为空时显示的内容string'Not Found'
dropdownMatchSelectWidth下拉菜单和选择器同宽true-
optionLabelProp回填到选择框的 Option 的属性值,默认是 Option 的子元素。比如在子元素需要高亮效果时,此值可以设为 valuestring/numberchildren (combobox 模式下为 value
combobox输入框自动提示模式boolfalse
size选择框大小,可选 lg smstringdefault
showSearch是否可以输入搜索boolfalse
supportWrite输入搜索查询时是否支持自定义输入,需配合showSearch使用,否则无效boolfalse
disabled是否禁用boolfalse
defaultActiveFirstOption是否默认高亮第一个选项booltrue
dropdownStyle下拉菜单的 style 属性object-
dropdownClassName下拉菜单的 className 属性string-
getPopupContainer菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位func() => document.body
labelInValue是否把每个选项的 label 包装到 value 中,决定 Select 的 value 类型。boolfalse
data可以设置data属性来自动生成option,可以参见demo中的示例。也可以设置是否禁用disabledArray-
autofocus设置是否默认打开,此属性需配合onFocus、onBlur 。boolfalse
onKeyDown按下键盘的回调func-
Children必填,Option组件/OptGroup组件node-

Option

参数说明类型默认值
key如果 react 需要你设置此项,此项值与 value 的值相同,然后可以省略 value 设置string-
value默认根据此属性值进行筛选string-
disabled是否禁用boolfalse

OptGroup

参数说明类型默认值
label组名string/react element-
modestring-
ChildrenOption组件node-

已支持的键盘操作

按键功能
↑(上箭)切换选项
↓(下箭)切换选项
esc关闭下拉项
enter选中下拉框

注意

在Modal组件中,使用Select组件时,需要使用getPopupContainer,来让下拉显示在modal上。

return (
    <Select
        getPopupContainer={() => document.getElementById('modalId')}>
    </Select>
)

开发调试

$ git clone https://github.com/tinper-bee/bee-select
$ cd bee-select
$ npm install
$ npm run dev
2.0.33

3 years ago

2.0.32

3 years ago

2.0.31

3 years ago

2.0.30

3 years ago

2.0.29

3 years ago

2.0.28

4 years ago

2.0.27-yonui.0

4 years ago

2.0.26

4 years ago

2.0.26-alpha.1

4 years ago

2.0.26-alpha.0

4 years ago

2.0.25

4 years ago

2.0.24

4 years ago

2.0.23

4 years ago

2.0.22

4 years ago

2.0.21

4 years ago

2.0.20

4 years ago

2.0.19

4 years ago

2.0.19-alpha.0

4 years ago

2.0.18

4 years ago

2.0.17

4 years ago

2.0.16

5 years ago

2.0.16-alpha.0

5 years ago

2.0.15

5 years ago

2.0.14

5 years ago

2.0.13

5 years ago

2.0.13-beta.0

5 years ago

2.0.12

5 years ago

2.0.11

5 years ago

2.0.10

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

1.1.11

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

1.1.10

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

1.1.9

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.0.27

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago