fix #IM0O7 实现动态输入框锁定 有锁定的情况下正确的响应输入 正确的判断输入框是否在输入状态.

pull/109/head
ChenX_AMD 6 years ago
parent 8a2d48dee6
commit ea3b85f227

@ -1,6 +1,6 @@
import { KeyBoard } from "../../Common/KeyEnum";
import { DynamicInputManage } from "./DynamicInputManage";
import { AutoReSize } from "../JsPlugin/InputAutoSize";
import { DynamicInputManage } from "./DynamicInputManage";
/**
*
@ -13,21 +13,48 @@ export class DynamicInput
{
//创建的新输入框
inputEl: HTMLInputElement;
lockEl: HTMLElement;
UpdateWidth: Function;
constructor(container: HTMLElement)
{
this.lockEl = document.createElement("span");
this.lockEl.className = "bp3-icon-standard bp3-icon-lock";
this.lockEl.style.border = "3px solid #999";
this.lockEl.style.background = "#f5f8fa";
this.lockEl.style.lineHeight = "inherit";
this.lockEl.style.height = "25px";
this.lockEl.style.display = "none";
container.appendChild(this.lockEl);
this.inputEl = document.createElement('input');
this.inputEl.style.pointerEvents = "none";
this.inputEl.style.minWidth = "15px";
this.inputEl.addEventListener("input", () => { this.OnInput() });
this.inputEl.addEventListener("keydown", e => { this.OnInputKeyDown(e) });
this.inputEl.addEventListener("change", () =>
{
this.Lock = true;
});
this.inputEl.style.border = "3px solid transparent";
container.appendChild(this.inputEl);
this.UpdateWidth = AutoReSize(this.inputEl).updateWidth;
this.Blur();
}
private m_Lock = false;
private m_HasLock = false;
set Lock(lock: boolean)
{
this.m_Lock = lock;
this.lockEl.style.display = lock ? "inline-block" : "none";
if (lock) this.m_HasLock = lock;
}
get Lock()
{
return this.m_Lock;
}
set Value(value: any)
{
if (this.m_Lock) return;
this.inputEl.value = value;
this.UpdateWidth();
this.SetSelect();
@ -59,7 +86,14 @@ export class DynamicInput
e.stopPropagation();
break;
}
DynamicInputManage.GetManage().IsInputing = true;
setTimeout(() =>
{
if (this.inputEl.selectionEnd - this.inputEl.selectionStart === 0)
{
DynamicInputManage.GetManage().IsInputing = true;
}
}, 16);
}
//激活焦点
public Focus()
@ -80,6 +114,9 @@ export class DynamicInput
this.inputEl.disabled = true;
this.inputEl.style.backgroundColor = '#999';
DynamicInputManage.GetManage().IsInputing = false;
if (this.m_HasLock) this.m_HasLock = false;
else this.Lock = false;
}
//设置位置
SetPosition(x, y)

@ -67,6 +67,10 @@ export class DynamicInputManage
{
return this.m_IsInputing;
}
get IsLockIng()
{
return this.inputCollection.some(i => i.Lock);
}
//获得容器节点
get Container(): HTMLElement

@ -39,14 +39,15 @@ export class RealDynamicInput extends DynamicInput
OnInputKeyDown(e: KeyboardEvent)
{
super.OnInputKeyDown(e);
let mng = DynamicInputManage.GetManage();
switch (e.keyCode)
{
case KeyBoard.Enter:
case KeyBoard.Space:
if (DynamicInputManage.GetManage().IsInputing)
DynamicInputManage.GetManage().HandleInputEvent(this.inputEl.value);
if (mng.IsInputing || mng.IsLockIng)
mng.HandleInputEvent(this.inputEl.value);
else
DynamicInputManage.GetManage().HandleInputEvent("");
mng.HandleInputEvent("");
e.stopPropagation();
break;
}

Loading…
Cancel
Save