Add enableLayoutCandidatesKeyPress option. Fixes #1866

This commit is contained in:
Francisco Hodge 2023-02-25 13:23:34 -05:00
parent a198d02259
commit b2872b7809
2 changed files with 19 additions and 1 deletions

View File

@ -135,6 +135,7 @@ class SimpleKeyboard {
* @property {number} layoutCandidatesPageSize Determines size of layout candidate list
* @property {boolean} layoutCandidatesCaseSensitiveMatch Determines whether layout candidate match should be case sensitive.
* @property {boolean} disableCandidateNormalization Disables the automatic normalization for selected layout candidates
* @property {boolean} enableLayoutCandidatesKeyPress Enables onKeyPress triggering for layoutCandidate items
*/
this.options = {
layoutName: "default",
@ -377,7 +378,11 @@ class SimpleKeyboard {
candidateValue,
targetElement,
onSelect: (selectedCandidate: string, e: MouseEvent) => {
const { layoutCandidatesCaseSensitiveMatch, disableCandidateNormalization } = this.options;
const {
layoutCandidatesCaseSensitiveMatch,
disableCandidateNormalization,
enableLayoutCandidatesKeyPress
} = this.options;
let candidateStr = selectedCandidate;
@ -413,6 +418,14 @@ class SimpleKeyboard {
this.setInput(newInput, this.options.inputName, true);
this.setCaretPosition(newCaretPosition);
/**
* Calling onKeyPress
* We pass in the composed candidate instead of the decomposed one
* To prevent confusion for users
*/
if (enableLayoutCandidatesKeyPress && typeof this.options.onKeyPress === "function")
this.options.onKeyPress(selectedCandidate, e);
if (typeof this.options.onChange === "function")
this.options.onChange(
this.getInput(this.options.inputName, true),

View File

@ -256,6 +256,11 @@ export interface KeyboardOptions {
*/
disableCandidateNormalization?: boolean;
/**
* Enables onKeyPress triggering for layoutCandidate items
*/
enableLayoutCandidatesKeyPress?: boolean;
/**
* Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
*/