mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-01-31 18:49:47 +08:00
Address upgrade issues
This commit is contained in:
parent
44cdc2bbb0
commit
fd0c48390d
@ -77,9 +77,9 @@ Want to create your own module? Check out the [Modules page](https://hodgef.com/
|
|||||||
> Simple-keyboard is intended for modern, standards-compliant browsers.
|
> Simple-keyboard is intended for modern, standards-compliant browsers.
|
||||||
> Internet Explorer is sadly not one of them, and since its market-share is negligible (~2% for IE11), resources won't be spent in trying to support it.
|
> Internet Explorer is sadly not one of them, and since its market-share is negligible (~2% for IE11), resources won't be spent in trying to support it.
|
||||||
>
|
>
|
||||||
> To learn more about the rationale for not supporting IE, check out [this link](https://techcommunity.microsoft.com/t5/Windows-IT-Pro-Blog/The-perils-of-using-Internet-Explorer-as-your-default-browser/ba-p/331732).
|
> For more information, check out [this Q&A entry](https://hodgef.com/simple-keyboard/questions-answers/internet-explorer-not-supported/).
|
||||||
|
|
||||||
## Contributing ✅
|
## Contributing ✅
|
||||||
|
|
||||||
PR's and issues are welcome. Feel free to submit any issues you have at:
|
PRs and issues are always welcome. Feel free to submit any issues you have at:
|
||||||
[https://github.com/hodgef/simple-keyboard/issues](https://github.com/hodgef/simple-keyboard/issues)
|
[https://github.com/hodgef/simple-keyboard/issues](https://github.com/hodgef/simple-keyboard/issues)
|
||||||
|
@ -4,10 +4,10 @@ import "./css/index.css";
|
|||||||
* Demos
|
* Demos
|
||||||
*/
|
*/
|
||||||
import BasicDemo from "./BasicDemo";
|
import BasicDemo from "./BasicDemo";
|
||||||
// import ButtonThemeDemo from "./ButtonThemeDemo";
|
//import ButtonThemeDemo from "./ButtonThemeDemo";
|
||||||
// import DOMElementDemo from "./DOMElementDemo";
|
//import DOMElementDemo from "./DOMElementDemo";
|
||||||
// import FullKeyboardDemo from "./FullKeyboardDemo";
|
//import FullKeyboardDemo from "./FullKeyboardDemo";
|
||||||
// import MultipleKeyboardsDemo from "./MultipleKeyboardsDestroyDemo";
|
//import MultipleKeyboardsDemo from "./MultipleKeyboardsDestroyDemo";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selected demo
|
* Selected demo
|
||||||
|
@ -27,7 +27,6 @@ class SimpleKeyboard {
|
|||||||
*/
|
*/
|
||||||
this.utilities = new Utilities({
|
this.utilities = new Utilities({
|
||||||
getOptions: this.getOptions,
|
getOptions: this.getOptions,
|
||||||
setCaretPosition: this.setCaretPosition,
|
|
||||||
getCaretPosition: this.getCaretPosition,
|
getCaretPosition: this.getCaretPosition,
|
||||||
getCaretPositionEnd: this.getCaretPositionEnd,
|
getCaretPositionEnd: this.getCaretPositionEnd,
|
||||||
dispatch: this.dispatch
|
dispatch: this.dispatch
|
||||||
@ -231,10 +230,10 @@ class SimpleKeyboard {
|
|||||||
/**
|
/**
|
||||||
* Setters
|
* Setters
|
||||||
*/
|
*/
|
||||||
setCaretPosition = (position, endPosition) => {
|
setCaretPosition(position, endPosition) {
|
||||||
this.caretPosition = position;
|
this.caretPosition = position;
|
||||||
this.caretPositionEnd = endPosition || position;
|
this.caretPositionEnd = endPosition || position;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles clicks made to keyboard buttons
|
* Handles clicks made to keyboard buttons
|
||||||
@ -544,10 +543,10 @@ class SimpleKeyboard {
|
|||||||
/**
|
/**
|
||||||
* inputName changed. This requires a caretPosition reset
|
* inputName changed. This requires a caretPosition reset
|
||||||
*/
|
*/
|
||||||
|
// TODO: Review side-effects
|
||||||
if (this.options.debug) {
|
if (this.options.debug) {
|
||||||
console.log("inputName changed. caretPosition reset.");
|
console.log("inputName changed. caretPosition reset.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setCaretPosition(null);
|
this.setCaretPosition(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -873,6 +872,8 @@ class SimpleKeyboard {
|
|||||||
`(${instance.keyboardDOMClass})`
|
`(${instance.keyboardDOMClass})`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Review side-effects
|
||||||
} else if (!isKeyboard) {
|
} else if (!isKeyboard) {
|
||||||
instance.setCaretPosition(null);
|
instance.setCaretPosition(null);
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,10 @@ class Utilities {
|
|||||||
/**
|
/**
|
||||||
* Creates an instance of the Utility service
|
* Creates an instance of the Utility service
|
||||||
*/
|
*/
|
||||||
constructor({
|
constructor({ getOptions, getCaretPosition, getCaretPositionEnd, dispatch }) {
|
||||||
getOptions,
|
|
||||||
setCaretPosition,
|
|
||||||
getCaretPosition,
|
|
||||||
getCaretPositionEnd,
|
|
||||||
dispatch
|
|
||||||
}) {
|
|
||||||
this.getOptions = getOptions;
|
this.getOptions = getOptions;
|
||||||
this.getCaretPosition = getCaretPosition;
|
this.getCaretPosition = getCaretPosition;
|
||||||
this.getCaretPositionEnd = getCaretPositionEnd;
|
this.getCaretPositionEnd = getCaretPositionEnd;
|
||||||
this.setCaretPosition = setCaretPosition;
|
|
||||||
this.dispatch = dispatch;
|
this.dispatch = dispatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -203,15 +196,10 @@ class Utilities {
|
|||||||
*/
|
*/
|
||||||
updateCaretPos(length, minus) {
|
updateCaretPos(length, minus) {
|
||||||
const newCaretPos = this.updateCaretPosAction(length, minus);
|
const newCaretPos = this.updateCaretPosAction(length, minus);
|
||||||
const { syncInstanceInputs } = this.getOptions();
|
|
||||||
|
|
||||||
if (syncInstanceInputs) {
|
|
||||||
this.dispatch(instance => {
|
this.dispatch(instance => {
|
||||||
instance.setCaretPosition(newCaretPos);
|
instance.setCaretPosition(newCaretPos);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
this.setCaretPosition(newCaretPos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -285,8 +273,6 @@ class Utilities {
|
|||||||
positionEnd = source.length,
|
positionEnd = source.length,
|
||||||
moveCaret = false
|
moveCaret = false
|
||||||
) {
|
) {
|
||||||
const { syncInstanceInputs } = this.getOptions();
|
|
||||||
|
|
||||||
if (position === 0 && positionEnd === 0) {
|
if (position === 0 && positionEnd === 0) {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
@ -328,13 +314,9 @@ class Utilities {
|
|||||||
} else {
|
} else {
|
||||||
output = source.slice(0, position) + source.slice(positionEnd);
|
output = source.slice(0, position) + source.slice(positionEnd);
|
||||||
if (moveCaret) {
|
if (moveCaret) {
|
||||||
if (syncInstanceInputs) {
|
|
||||||
this.dispatch(instance => {
|
this.dispatch(instance => {
|
||||||
instance.setCaretPosition(position);
|
instance.setCaretPosition(position);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
this.setCaretPosition(position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,11 +490,11 @@ it('Keyboard removeAt will propagate caretPosition', () => {
|
|||||||
keyboard.getButtonElement('{bksp}').onclick();
|
keyboard.getButtonElement('{bksp}').onclick();
|
||||||
|
|
||||||
expect(keyboard.getCaretPosition()).toBe(1);
|
expect(keyboard.getCaretPosition()).toBe(1);
|
||||||
expect(keyboard2.getCaretPosition()).toBe(null);
|
expect(keyboard2.getCaretPosition()).toBe(1);
|
||||||
|
|
||||||
expect(keyboard.getInput()).toBe('hlo');
|
expect(keyboard.getInput()).toBe('hlo');
|
||||||
expect(keyboard.getCaretPositionEnd()).toBe(1);
|
expect(keyboard.getCaretPositionEnd()).toBe(1);
|
||||||
expect(keyboard2.getCaretPositionEnd()).toBe(null);
|
expect(keyboard2.getCaretPositionEnd()).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Keyboard removeAt will propagate caretPosition in a syncInstanceInputs setting', () => {
|
it('Keyboard removeAt will propagate caretPosition in a syncInstanceInputs setting', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user