bug fixed
This commit is contained in:
@@ -273,7 +273,7 @@ class Framework extends Component{
|
||||
//如果是禁用状态, 不能进行操作
|
||||
if(itemDisabled) return;
|
||||
|
||||
if(item[optgroup] && (tree.strict || cascader.strict)){
|
||||
if(item[optgroup] && (tree.show && tree.strict || cascader.show && cascader.strict)){
|
||||
let child = item[children], change = [], isAdd = true, handlerType;
|
||||
if(item.__node.selected){
|
||||
handlerType = 'del';
|
||||
@@ -540,10 +540,15 @@ class Framework extends Component{
|
||||
//监听键盘事件
|
||||
this.base.addEventListener('keydown', e => {
|
||||
let keyCode = e.keyCode;
|
||||
//ENTER
|
||||
if(keyCode === 13){
|
||||
this.onClick()
|
||||
this.onClick(e)
|
||||
}
|
||||
});
|
||||
|
||||
// focus 可以监听tab切换
|
||||
// this.base.addEventListener('focus', e => {
|
||||
// })
|
||||
|
||||
//表单验证
|
||||
this.input = this.base.querySelector('.xm-select-default');
|
||||
@@ -558,7 +563,7 @@ class Framework extends Component{
|
||||
this.input.className = 'xm-select-default';
|
||||
this.base.style.borderColor = this.props.theme.maxColor;
|
||||
//这里可以自己新增一个回调, 也许看到源码的你能够看到
|
||||
// this.base.scrollIntoView({ behavior: "smooth" });
|
||||
this.base.scrollIntoView && this.base.scrollIntoView({ behavior: "smooth" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -578,6 +583,8 @@ class Framework extends Component{
|
||||
dom = dom.parentElement;
|
||||
}
|
||||
|
||||
let { done } = this.props;
|
||||
done && done();
|
||||
}
|
||||
|
||||
//此时页面又被重新渲染了
|
||||
|
||||
@@ -87,7 +87,7 @@ class General extends Component{
|
||||
}
|
||||
}
|
||||
|
||||
searchInput(e){
|
||||
searchInput(e){
|
||||
let v = e.target.value;
|
||||
|
||||
if(v === this.__value){
|
||||
@@ -115,7 +115,7 @@ class General extends Component{
|
||||
this.searchInputRef && this.searchInputRef.blur();
|
||||
}
|
||||
|
||||
handleComposition(e){
|
||||
handleComposition(e){
|
||||
let type = e.type;
|
||||
|
||||
if(type === 'compositionstart'){
|
||||
@@ -164,7 +164,7 @@ class General extends Component{
|
||||
this.pageNextClick();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(this.props.enableKeyboard){
|
||||
const { value, optgroup, disabled } = this.props.prop;
|
||||
let data = this.tempData.filter(item => !item[optgroup] && !item[disabled]);
|
||||
@@ -172,7 +172,7 @@ class General extends Component{
|
||||
if(len === -1){
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
let index = data.findIndex(item => item[value] === this.state.val);
|
||||
//Up 键
|
||||
if(keyCode === 38){
|
||||
@@ -183,9 +183,7 @@ class General extends Component{
|
||||
}
|
||||
let val = data[index][value];
|
||||
this.setState({ val })
|
||||
//键盘选中时滚动到可视范围内
|
||||
let opt = this.base.querySelector(`.xm-option[value="${ val }"]`);
|
||||
opt && opt.scrollIntoView(false)
|
||||
this.viewTo(val);
|
||||
}else
|
||||
//Down 键
|
||||
if(keyCode === 40){
|
||||
@@ -196,19 +194,24 @@ class General extends Component{
|
||||
}
|
||||
let val = data[index][value];
|
||||
this.setState({ val })
|
||||
//键盘选中时滚动到可视范围内
|
||||
let opt = this.base.querySelector(`.xm-option[value="${ val }"]`);
|
||||
opt && opt.scrollIntoView(false)
|
||||
this.viewTo(val);
|
||||
}else
|
||||
//Enter 键
|
||||
if(keyCode === 13){
|
||||
if(keyCode === this.props.selectedKeyCode){
|
||||
if(this.state.val != emptyVal){
|
||||
let option = data[index];
|
||||
this.optionClick(option, this.props.sels.findIndex(item => item[value] === this.state.val) != -1, option[disabled], e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewTo(val){
|
||||
//键盘选中时滚动到可视范围内
|
||||
if(void 0 != this.base){
|
||||
let opt = this.base.querySelector(`.xm-option[value="${ val }"]`);
|
||||
opt && opt.scrollIntoView(false)
|
||||
}
|
||||
}
|
||||
|
||||
//组件将要接收新属性
|
||||
@@ -239,7 +242,7 @@ class General extends Component{
|
||||
}
|
||||
|
||||
render(config) {
|
||||
let { data, flatData, prop, template, theme, radio, sels, empty, filterable, filterMethod, remoteSearch, remoteMethod, delay, searchTips, create, pageRemote, max, enableKeyboard } = config
|
||||
let { data, flatData, prop, template, theme, radio, sels, empty, filterable, filterMethod, remoteSearch, remoteMethod, delay, searchTips, create, pageRemote, max, enableKeyboard, enableHoverFirst } = config
|
||||
|
||||
const { name, value, disabled, children, optgroup } = prop;
|
||||
|
||||
@@ -358,8 +361,10 @@ class General extends Component{
|
||||
|
||||
//查看是否创建了条目
|
||||
if(creator){
|
||||
creator = create(this.state.filterValue, deepMerge([], arr));
|
||||
creator && arr.splice(0, 0, {...creator, __node: {}});
|
||||
creator = create(this.state.filterValue, deepMerge([], arr));
|
||||
if(void 0 != creator){
|
||||
arr.splice(0, 0, ...(isArray(creator) ? creator : [creator]).map(i => ({ ...i, __node: {} })));
|
||||
}
|
||||
}
|
||||
|
||||
let safetyArr = deepMerge([], arr);
|
||||
@@ -521,10 +526,14 @@ class General extends Component{
|
||||
|
||||
arr = arr.map(renderGroup);
|
||||
|
||||
if(!arr.length){
|
||||
if(arr.length){
|
||||
if(enableHoverFirst && this.state.val == emptyVal){
|
||||
this.keydown('div', { keyCode: 40 })
|
||||
}
|
||||
}else{
|
||||
//查看无数据情况下是否显示分页
|
||||
!config.pageEmptyShow && (paging = '');
|
||||
arr.push(<div class="xm-select-empty">{ empty }</div>)
|
||||
arr.push(<div class="xm-select-empty">{ empty }</div>)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -20,6 +20,7 @@ class Tree extends Component{
|
||||
this.inputOver = true;
|
||||
this.__value = '';
|
||||
this.tempData = [];
|
||||
this.__skipAutoExpand = '';
|
||||
}
|
||||
|
||||
init(props){
|
||||
@@ -59,7 +60,7 @@ class Tree extends Component{
|
||||
|
||||
const { tree, prop, sels } = this.props;
|
||||
const { clickExpand, clickCheck } = tree;
|
||||
|
||||
|
||||
//检测点击的是不是三角箭头
|
||||
let isExpand = e.target && isFunction(e.target.getAttribute) && e.target.getAttribute('type') === 'expand'
|
||||
//如果点击即展开
|
||||
@@ -180,10 +181,13 @@ class Tree extends Component{
|
||||
}
|
||||
|
||||
if(!hiddenStatus){//如果是显示状态
|
||||
let keys = this.state.expandedKeys;
|
||||
if(val && keys.findIndex(key => key === item[value]) === -1){
|
||||
keys.push(item[value]);
|
||||
this.setState({ expandedKeys: keys })
|
||||
if(this.__skipAutoExpand != val){//第一次搜索默认展开过滤后的数据
|
||||
let keys = this.state.expandedKeys;
|
||||
if(val && keys.findIndex(key => key === item[value]) === -1){
|
||||
keys.push(item[value]);
|
||||
this.setState({ expandedKeys: keys })
|
||||
}
|
||||
this.__skipAutoExpand = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,6 +220,7 @@ class Tree extends Component{
|
||||
//清空输入框的值
|
||||
this.setState({ filterValue: '', val: emptyVal });
|
||||
this.__value = '';
|
||||
this.__skipAutoExpand = '';
|
||||
this.searchInputRef && (this.searchInputRef.value = '');
|
||||
}else{
|
||||
//聚焦输入框
|
||||
|
||||
@@ -80,7 +80,11 @@ export default function (lan = 'zn') {
|
||||
//选项显示数量
|
||||
showCount: 0,
|
||||
//是否开启键盘操作
|
||||
enableKeyboard: true,
|
||||
enableKeyboard: true,
|
||||
//开启键盘操作后是否默认选中第一条
|
||||
enableHoverFirst: true,
|
||||
//键盘选中的KeyCode, 默认是Enter
|
||||
selectedKeyCode: 13,
|
||||
//工具条
|
||||
toolbar: {
|
||||
show: false,
|
||||
@@ -187,6 +191,9 @@ export default function (lan = 'zn') {
|
||||
},
|
||||
submitConversion(sels, prop){
|
||||
return sels.map(item => item[prop.value]).join(',')
|
||||
},
|
||||
done(){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ export default {
|
||||
name,
|
||||
version,
|
||||
doc: website,
|
||||
KeyCode: {
|
||||
Enter: 13,
|
||||
Space: 32,
|
||||
},
|
||||
render(options) {
|
||||
let { el } = options;
|
||||
options.dom = selector(el);
|
||||
|
||||
@@ -61,7 +61,7 @@ xm-select{
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
|
||||
&:hover{
|
||||
&:hover,&:focus{
|
||||
border-color: #C0C4CC;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user