Date: Wed, 25 Sep 2019 15:10:19 +0800
Subject: [PATCH 3/7] fix(Select): ignore case when search (#659ʡ)
---
components/select/Select.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/components/select/Select.js b/components/select/Select.js
index 03f49f11d..93e9ea3cb 100644
--- a/components/select/Select.js
+++ b/components/select/Select.js
@@ -418,7 +418,7 @@ class Select extends Component {
onFilterItems(keyword) {
this.setState(
{
- keyword
+ keyword: keyword.toLowerCase()
},
() => this.resetFocusedIndex()
)
@@ -438,8 +438,8 @@ class Select extends Component {
return (
this.isRemote() ||
(!searchable || !keyword) ||
- (String(item.id).includes(keyword) ||
- String(item.title).includes(keyword))
+ (String(item.id).toLowerCase().includes(keyword) ||
+ String(item.title).toLowerCase().includes(keyword))
)
}
From 6a535622aff3171bdc117fd604e0e6fe5c20b7ad Mon Sep 17 00:00:00 2001
From: Bougie <1742070326@qq.com>
Date: Wed, 25 Sep 2019 15:16:03 +0800
Subject: [PATCH 4/7] docs(Menu): fix spelling mistake
---
docs/zh-CN/components/menu.mdx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/zh-CN/components/menu.mdx b/docs/zh-CN/components/menu.mdx
index b0ffe96a9..2e7cfc338 100755
--- a/docs/zh-CN/components/menu.mdx
+++ b/docs/zh-CN/components/menu.mdx
@@ -47,7 +47,7 @@ import { Badge } from '@libs'
| activeId | 激活的菜单项 id | string | - | - |
| placement | 设置菜单水平或垂直展示 | string | 'horizontal' \| 'vertical' | 'vertical' |
| collapsed | 是否收起子菜单,菜单垂直展示时有效 | boolean | true \| false | false |
-| showCollpse | 是否显示收缩开关,菜单垂直展示时有效 | boolean | true \| false | true |
+| showCollapse | 是否显示收缩开关,菜单垂直展示时有效 | boolean | true \| false | true |
| showAllSubMenus | 是否展开所有菜单 | boolean | true \| false | false |
| accordion | 手风琴模式,菜单水平展示时有效 | boolean | true \| false | true |
| onClick | 点击菜单选项时的回调 | (activeId, prevActiveId) => void | - | - |
From b6a0f8e7a64a9c971a6168ed636dc1f06daae3c7 Mon Sep 17 00:00:00 2001
From: Bougie <1742070326@qq.com>
Date: Wed, 25 Sep 2019 15:37:43 +0800
Subject: [PATCH 5/7] fix(Pagination): #691
---
components/pagination/Pagination.js | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/components/pagination/Pagination.js b/components/pagination/Pagination.js
index 642e39062..d19a110e8 100644
--- a/components/pagination/Pagination.js
+++ b/components/pagination/Pagination.js
@@ -1,7 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Pager from './Pager'
-import Dropdown from '../dropdown/index'
+import Select from '../select'
import Input from '../input'
import Provider from '../context'
@@ -158,17 +158,18 @@ class Pagination extends Component {
return (
{
const val = e.target.value
+ if (!val) {
+ this.setState({
+ jumpTo: val
+ })
+ return
+ }
if (/^\d+$/.test(val)) {
const maxPage = this.calculatePage(total)
const jumpTo = val < 1 ? 1 : (val > maxPage ? maxPage : val)
From 7634ef6b971034ec36dc6266523490961514a770 Mon Sep 17 00:00:00 2001
From: Bougie <1742070326@qq.com>
Date: Wed, 25 Sep 2019 17:01:28 +0800
Subject: [PATCH 6/7] fix(Pagination): Jumper blur
---
components/_util/SwitchVersion.js | 16 ++++----
components/input/Input.js | 4 ++
components/pagination/Pagination.js | 60 ++++++++++++++---------------
3 files changed, 41 insertions(+), 39 deletions(-)
diff --git a/components/_util/SwitchVersion.js b/components/_util/SwitchVersion.js
index 783cf6d8c..d11777061 100644
--- a/components/_util/SwitchVersion.js
+++ b/components/_util/SwitchVersion.js
@@ -1,16 +1,14 @@
import React, { forwardRef } from 'react'
function SwitchVersion (component = {}, componentLegacy = {}) {
- const WrapperComponent = ({ legacy, innerRef, ...props }) => {
- const innerComponent = legacy === true ? componentLegacy : component
- return React.createElement(
- innerComponent,
- Object.assign({}, props, { ref: innerRef })
- )
- }
- return forwardRef((props, ref) => {
- return
+ const WrapperComponent = forwardRef(({ legacy, ...props }, ref) => {
+ const InnerComponent = legacy === true ? componentLegacy : component
+ for (const staticProp in InnerComponent) {
+ WrapperComponent[staticProp] = InnerComponent[staticProp]
+ }
+ return
})
+ return WrapperComponent
}
export default SwitchVersion
diff --git a/components/input/Input.js b/components/input/Input.js
index 8ff062437..01747fffb 100644
--- a/components/input/Input.js
+++ b/components/input/Input.js
@@ -70,6 +70,10 @@ class Input extends Component {
}
}
+ blur = () => {
+ this._Input.blur()
+ }
+
/**
* 渲染 text 输入框
*/
diff --git a/components/pagination/Pagination.js b/components/pagination/Pagination.js
index d19a110e8..c6baafdc4 100644
--- a/components/pagination/Pagination.js
+++ b/components/pagination/Pagination.js
@@ -18,35 +18,6 @@ function breakItemRender (page, element) {
function noop () {}
class Pagination extends Component {
- static propTypes = {
- defaultCurrent: PropTypes.number,
- pageSize: PropTypes.number,
- max: PropTypes.number,
- showJumper: PropTypes.bool,
- autoHide: PropTypes.bool,
- total: PropTypes.number,
- onChange: PropTypes.func,
- itemRender: PropTypes.func,
- onPageSizeChange: PropTypes.func,
- onJump: PropTypes.func,
- pageSizeOptions: PropTypes.array,
- type: PropTypes.oneOf(['simple', 'default', 'shrink'])
- }
-
- static defaultProps = {
- pageSizeOptions: [],
- showJumper: false,
- autoHide: false,
- type: 'default',
- defaultCurrent: 1,
- pageSize: 10,
- max: 2,
- total: 0,
- onChange: noop,
- className: '',
- prefixCls: 'hi-pagination'
- }
-
constructor (props) {
super(props)
@@ -233,7 +204,7 @@ class Pagination extends Component {
} else if (e.type === 'keypress') {
if (e.charCode === 13) {
setPageNum(pageNum)
- this.jumper.current._Input.blur()
+ this.jumper.current.blur()
}
}
}
@@ -429,4 +400,33 @@ class Pagination extends Component {
}
}
+Pagination.propTypes = {
+ defaultCurrent: PropTypes.number,
+ pageSize: PropTypes.number,
+ max: PropTypes.number,
+ showJumper: PropTypes.bool,
+ autoHide: PropTypes.bool,
+ total: PropTypes.number,
+ onChange: PropTypes.func,
+ itemRender: PropTypes.func,
+ onPageSizeChange: PropTypes.func,
+ onJump: PropTypes.func,
+ pageSizeOptions: PropTypes.array,
+ type: PropTypes.oneOf(['simple', 'default', 'shrink'])
+}
+
+Pagination.defaultProps = {
+ pageSizeOptions: [],
+ showJumper: false,
+ autoHide: false,
+ type: 'default',
+ defaultCurrent: 1,
+ pageSize: 10,
+ max: 2,
+ total: 0,
+ onChange: noop,
+ className: '',
+ prefixCls: 'hi-pagination'
+}
+
export default Provider(Pagination)
From 22267767bb901d62ff54af7066c99a18c82e3de0 Mon Sep 17 00:00:00 2001
From: Bougie <1742070326@qq.com>
Date: Thu, 26 Sep 2019 14:09:00 +0800
Subject: [PATCH 7/7] fix(Select): custom filter (#673)
---
components/select/Select.js | 47 +++++++++++++-----------
docs/demo/select/section-search.jsx | 51 ++++++++++++++++++++++++++
docs/zh-CN/components/select.mdx | 57 +++++++++++++++++------------
3 files changed, 109 insertions(+), 46 deletions(-)
create mode 100644 docs/demo/select/section-search.jsx
diff --git a/components/select/Select.js b/components/select/Select.js
index 93e9ea3cb..28f8df47a 100644
--- a/components/select/Select.js
+++ b/components/select/Select.js
@@ -35,6 +35,7 @@ class Select extends Component {
showCheckAll: PropTypes.bool,
autoload: PropTypes.bool,
searchable: PropTypes.bool,
+ filterOption: PropTypes.func,
clearable: PropTypes.bool,
disabled: PropTypes.bool,
placeholder: PropTypes.string,
@@ -149,7 +150,7 @@ class Select extends Component {
if (this.isRemote()) {
return true
}
- return !!searchable
+ return searchable
}
parseValue (value = this.props.value) {
@@ -170,7 +171,7 @@ class Select extends Component {
resetSelectedItems (value, dropdownItems = [], listChanged = false) {
const values = this.parseValue(value)
let selectedItems = []
- dropdownItems.forEach(item => {
+ dropdownItems.forEach((item) => {
if (values.includes(item.id)) {
selectedItems.push(item)
}
@@ -247,11 +248,9 @@ class Select extends Component {
}
this.onChange(selectedItems, item, () => {
- this.setState(
- {
- focusedIndex
- }
- )
+ this.setState({
+ focusedIndex
+ })
})
if (this.props.type !== 'multiple') {
this.hideDropdown()
@@ -350,11 +349,10 @@ class Select extends Component {
: keyword
this.autoloadFlag = false // 第一次自动加载数据后,输入的关键词即使为空也不再使用默认关键词
- const queryParams = qs.stringify(Object.assign({}, params, key && {[key]: keyword}))
- url =
- url.includes('?')
- ? `${url}&${queryParams}`
- : `${url}?${queryParams}`
+ const queryParams = qs.stringify(
+ Object.assign({}, params, key && { [key]: keyword })
+ )
+ url = url.includes('?') ? `${url}&${queryParams}` : `${url}?${queryParams}`
if (type.toUpperCase() === 'POST') {
options.body = JSON.stringify(data)
@@ -418,7 +416,7 @@ class Select extends Component {
onFilterItems(keyword) {
this.setState(
{
- keyword: keyword.toLowerCase()
+ keyword: keyword
},
() => this.resetFocusedIndex()
)
@@ -434,13 +432,18 @@ class Select extends Component {
}
matchFilter(item) {
+ const { filterOption } = this.props
const { searchable, keyword } = this.state
- return (
- this.isRemote() ||
- (!searchable || !keyword) ||
- (String(item.id).toLowerCase().includes(keyword) ||
- String(item.title).toLowerCase().includes(keyword))
- )
+
+ const shouldMatch = this.isRemote() ||
+ (!searchable || !keyword)
+
+ if (typeof filterOption === 'function') {
+ return shouldMatch || filterOption(keyword, item)
+ }
+
+ return shouldMatch || (String(item.id).includes(keyword) ||
+ String(item.title).includes(keyword))
}
resetFocusedIndex(setState = true) {
@@ -539,7 +542,7 @@ class Select extends Component {
style={style}
>
{
this.selectInputContainer = node
}}
@@ -579,8 +582,8 @@ class Select extends Component {
attachEle={this.selectInputContainer}
zIndex={1050}
topGap={5}
- className="hi-select__popper"
- placement="top-bottom-start"
+ className='hi-select__popper'
+ placement='top-bottom-start'
>
{
+ console.log('单选结果', item)
+ }}
+ searchable
+ filterOption={(keyword, item) => {
+ keyword = parseInt(keyword)
+ return item.id >= keyword
+ }}
+ />
+ )
+ }
+}`
+
+const DemoBan = () => (
+
+)
+export default DemoBan
diff --git a/docs/zh-CN/components/select.mdx b/docs/zh-CN/components/select.mdx
index 017e941dd..65435f7e2 100755
--- a/docs/zh-CN/components/select.mdx
+++ b/docs/zh-CN/components/select.mdx
@@ -28,6 +28,12 @@ import DemoCustom from '../../demo/select/section-custom'
+## 自定义搜索
+
+import DemoSearch from '../../demo/select/section-search'
+
+
+
## 异步单选
import DemoAsync from '../../demo/select/section-async'
@@ -46,37 +52,40 @@ import DemoAsyncMultiple from '../../demo/select/section-async-multiple'
+import { Badge } from '@libs'
+
## Props
-| 参数 | 说明 | 类型 | 可选值 | 默认值 |
-| ------------ | ------------------------------------------------------------ | ----------------------------------------------------- | ---------------------- | -------- |
-| type | 下拉框类型 | string | 'single' \| 'multiple' | 'single' |
-| data | 下拉框选项数据源 | DataItem[] | - | - |
-| dataSource | 异步下拉框选项数据源 | DataSource | - | - |
-| value | 被选中项的值 | string \| string[] | - | - |
-| defaultValue | 默认被选中项的值 | string \| string[] | - | - |
-| showCheckAll | 是否显示全选,只对多选生效 | boolean | true \| false | false |
-| multipleWrap | 多选模式下是否允许选中结果折行,不建议折行因为会变成动态高度 | string | 'wrap' \| 'nowrap' | 'nowrap' |
-| searchable | 是否可以筛选 | boolean | true \| false | false |
-| clearable | 是否可以清空 | boolean | true \| false | true |
-| autoload | origin 从远端获取数据,初始时是否自动加载 | boolean | true \| false | false |
-| disabled | 是否禁用 | boolean | true \| false | false |
-| placeholder | 输入框占位 | string | - | 请选择 |
-| emptyContent | 没有选项时的提示 | string \| ReactNode | - | 无内容 |
-| style | 自定义样式 | object | - | |
-| optionWidth | 自定义下拉选项宽度 | number | - | |
-| onChange | 改变选项时触发函数,回调值为当前所有选中项的 id 和变更项 | (selectedIds:stirng[], changedItem: DataItem) => void | - | 无内容 |
-| render | 自定义下拉菜单渲染函数,回调值为选项数据和是否被选中 | (item: DataItem, selected: boolean) => ReactNode | - | 无内容 |
+| 参数 | 说明 | 类型 | 可选值 | 默认值 |
+| ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | -------------------------------------------- | -------- |
+| type | 下拉框类型 | string | 'single' \| 'multiple' | 'single' |
+| data | 下拉框选项数据源 | DataItem[] | - | - |
+| dataSource | 异步下拉框选项数据源 | DataSource | - | - |
+| value | 被选中项的值 | string \| string[] | - | - |
+| defaultValue | 默认被选中项的值 | string \| string[] | - | - |
+| showCheckAll | 是否显示全选,只对多选生效 | boolean | true \| false | false |
+| multipleWrap | 多选模式下是否允许选中结果折行,不建议折行因为会变成动态高度 | string | 'wrap' \| 'nowrap' | 'nowrap' |
+| searchable | 是否可以筛选 | boolean | true \| false | false |
+| filterOption
| 第一个参数为输入的关键字,第二个为数据项,返回值为 true 时将出现在结果项。仅在 searchable 为 true 时有效 | (keyword: string, item: DataItem) => boolean | (keyword: string, item: DataItem) => boolean | - |
+| clearable | 是否可以清空 | boolean | true \| false | true |
+| autoload | origin 从远端获取数据,初始时是否自动加载 | boolean | true \| false | false |
+| disabled | 是否禁用 | boolean | true \| false | false |
+| placeholder | 输入框占位 | string | - | 请选择 |
+| emptyContent | 没有选项时的提示 | string \| ReactNode | - | 无内容 |
+| style | 自定义样式 | object | - | |
+| optionWidth | 自定义下拉选项宽度 | number | - | |
+| onChange | 改变选项时触发函数,回调值为当前所有选中项的 id 和变更项 | (selectedIds:stirng[], changedItem: DataItem) => void | - | 无内容 |
+| render | 自定义下拉菜单渲染函数,回调值为选项数据和是否被选中 | (item: DataItem, selected: boolean) => ReactNode | - | 无内容 |
## Type
### DataItem
-| 参数 | 说明 | 类型 | 可选值 | 默认值 |
-| -------- | --------------- | ------ | --------------- | ------ |
-| title | 下拉选项标题 | string | - | - |
-| id | 下拉选项唯一 id | string | 'get' \| 'post' | 'get' |
-| disabled | 是否禁用 | object | - | - |
+| 参数 | 说明 | 类型 | 可选值 | 默认值 |
+| -------- | --------------- | ---------------- | ------ | ------ |
+| title | 下拉选项标题 | string | - | - |
+| id | 下拉选项唯一 id | string \| number | - | - |
+| disabled | 是否禁用 | object | - | - |
### DataSource