パッケージの詳細

bee-select

tinper-bee681MIT2.0.35

select ui component for react

react, react-component, react-select, iuap-design

readme

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 控制下拉框展开收起 bool false
value 指定当前选中的条目 string/array/react node -
defaultValue 指定默认选中的条目 string/array/react node -
multiple 支持多选 bool false
allowClear 支持清除, 单选模式有效 bool false
filterOption 是否根据输入项进行筛选。当其为一个函数时,会接收 inputValue option 两个参数,当 option 符合筛选条件时,应返回 true,反之则返回 false bool/func true
tags 可以把随意输入的条目作为 tag,输入项不需要与下拉选项匹配 bool false
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 的子元素。比如在子元素需要高亮效果时,此值可以设为 value string/number children (combobox 模式下为 value
combobox 输入框自动提示模式 bool false
size 选择框大小,可选 lg sm string default
showSearch 是否可以输入搜索 bool false
supportWrite 输入搜索查询时是否支持自定义输入,需配合showSearch使用,否则无效 bool false
disabled 是否禁用 bool false
defaultActiveFirstOption 是否默认高亮第一个选项 bool true
dropdownStyle 下拉菜单的 style 属性 object -
dropdownClassName 下拉菜单的 className 属性 string -
getPopupContainer 菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位 func () => document.body
labelInValue 是否把每个选项的 label 包装到 value 中,决定 Select 的 value 类型。 bool false
data 可以设置data属性来自动生成option,可以参见demo中的示例。也可以设置是否禁用disabled Array -
autofocus 设置是否默认打开,此属性需配合onFocus、onBlur 。 bool false
onKeyDown 按下键盘的回调 func -
Children 必填,Option组件/OptGroup组件 node -

Option

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

OptGroup

参数 说明 类型 默认值
label 组名 string/react element -
mode string -
Children Option组件 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.32 (2021-01-20)

Bug Fixes

  • 超出最大长度隐藏的选项在hover时显示具体名称 (0b4c004)

2.0.31 (2021-01-19)

Bug Fixes

  • 超出最大长度隐藏的选项在hover时显示具体名称 (330533f)

2.0.30 (2020-12-21)

Features

  • 新增userSelectText参数(布尔值),为true时可选中输入框内的值用于复制等场景 (d4d1c7a)

2.0.29 (2020-10-27)

Bug Fixes

  • 超出最大长度隐藏的选项在hover时显示具体名称 (b3f1736)

2.0.28 (2020-10-15)

2.0.26 (2020-07-17)

Bug Fixes

  • Select下拉组件的placeHolder不显示[#536] (b0edb85)

2.0.25 (2020-05-08)

Features

  • noWarp时 宽度计算优化 (0ceb5be)

2.0.24 (2020-05-07)

Bug Fixes

2.0.23 (2020-04-26)

Bug Fixes

2.0.22 (2020-04-24)

Bug Fixes

2.0.21 (2020-04-23)

Features

  • bee-select: 新增noWarp属性,多选超过宽度显示+n... (590946d)

2.0.20 (2020-04-20)

Bug Fixes

  • bee-select: child type 适配 (24a0810)

2.0.19 (2020-04-14)

Bug Fixes

  • bee-select: forcePopupAlign方法加合法校验 (9e9ba03)

Features

  • 增加参数openDropdownWhenFocus,支持聚焦时自动展开下拉面板 (0fbad97)

2.0.18 (2019-11-19)

2.0.17 (2019-11-04)

2.0.16 (2019-09-23)

2.0.15 (2019-07-29)

Bug Fixes

  • bee-select: MenuItem引入方式改为从 lib中 (c50ffd5)

2.0.14 (2019-07-08)

2.0.13 (2019-06-01)

2.0.12 (2019-05-13)

Features

  • bee-select: 输入搜索查询时支持自定义输入 (0a4d90b)

2.0.11 (2019-04-25)

Features

  • bee-select: 新增下拉框popData自定义属性 (3a9fed7)

2.0.10 (2019-04-23)

Features

  • bee-select: 新增onKeyDown回调,enterKeyDown开关 (59fdfa2)

2.0.9 (2019-04-10)

2.0.7 (2019-03-18)

Bug Fixes

  • bee-select: 多选配合form使用设置初始值为字符串时,去掉报错,给警告 (a36d4db)

2.0.6 (2019-03-18)

Bug Fixes

  • bee-select: 多选配合form使用保存bug (21d2c56)

2.0.5 (2019-03-18)

Bug Fixes

  • bee-select: 多选配合form使用报错问题 (366d1a3)

2.0.4 (2019-03-05)

2.0.3 (2019-03-04)

2.0.2 (2019-03-04)

Bug Fixes

  • bee-select: export 问题 (77fc595)

2.0.1 (2019-02-28)

1.1.8 (2019-01-15)

Bug Fixes

  • bee-select: 下拉item高度改为30px (8e6a83d)

1.1.7 (2019-01-11)

Bug Fixes

  • bee-select: 行高调整 (3e2e57e)

1.1.6 (2019-01-11)

Bug Fixes

  • bee-select: 修改Trigger从bee-overlay引入 (c31e336)

1.1.5 (2018-11-22)

Features

  • bee-select: 下拉箭头触发focus (2ab192a)

1.1.4 (2018-11-16)

Bug Fixes

  • bee-select: 多选下拉箭头 (e6b7a1a)

1.1.3 (2018-11-15)

Features

  • bee-select: onClick出发onFocus (98c900a)

1.1.2 (2018-11-15)

Bug Fixes

1.1.1 (2018-11-15)

Features

  • bee-select: 键盘操作功能 (c59f1eb)

1.0.26 (2018-11-15)

Features

  • bee-select: 键盘快捷键bug修改 (e325eeb)

1.0.25 (2018-11-13)

Features

  • bee-select: 升级bee-menus (fc96b00)

1.0.24 (2018-11-13)

Features

  • bee-select: 优化计算宽度时机 (5df58b7)

1.0.23 (2018-11-09)

Bug Fixes

  • bee-select: 还原宽度计算 (8d66d44)

1.0.22 (2018-11-02)

Bug Fixes

  • bee-select: 下拉框触发focus,宽度计算时机修改 (64a2137)

1.0.21 (2018-10-16)

Bug Fixes

  • bee-select: onFocus触发两次 (f6167db)

1.0.20 (2018-10-15)

Bug Fixes

  • bee-select: 多选闪烁bug (49fbe60)

1.0.19 (2018-10-11)

1.0.18 (2018-10-11)

1.0.17 (2018-10-11)

Features

  • bee-select: 文档修改,配合2.0form,失去焦点校验报错问题 (fedec00)

1.0.16 (2018-09-30)

1.0.13 (2018-09-06)

1.0.12 (2018-09-01)

1.0.11 (2018-08-16)

1.0.9 (2018-06-08)

1.0.8 (2018-04-25)

  • fix(搜索的时候会一直报错Uncaught TypeError: menu.onKeyDown is not a function): (2830c2f), closes #8

Bug Fixes

  • proptypes error (0df3382)
  • selectTrigger.js: 解决了点击下拉框宽度显示不正常的问题 (1ff56be)
  • selectTrigger.js: 解决显示控件不够的时候会闪动两下 (2e1f073)
  • 修改示例 (f1740ba)

build

  • 组件依赖、changelog: 组件依赖、changelog (da559fe)

Features

  • "autofocus 支持默认选中": "autofocus 支持默认选中" (2cf2f31), closes #98
  • select.js: 增加data属性来自动生成option选项,并增加示例和文档 (4299774)

BREAKING CHANGES

  • "autofocus 支持默认选中": "autofocus 支持默认选中"
  • 搜索的时候会一直报错Uncaught TypeError: menu.onKeyDown is not a function
  • 组件依赖、changelog: 组件依赖、changelog