Using display options with layoutCandidates. Fixes #1831

This commit is contained in:
Francisco Hodge 2023-01-04 01:48:06 -05:00
parent 040d4fc40f
commit 5e1df22e59
10 changed files with 20 additions and 12 deletions

View File

@ -1,12 +1,13 @@
import "./css/CandidateBox.css";
import Utilities from "../services/Utilities";
import { CandidateBoxParams, CandidateBoxRenderParams, CandidateBoxShowParams } from "./../interfaces";
import { CandidateBoxParams, CandidateBoxRenderParams, CandidateBoxShowParams, KeyboardOptions } from "./../interfaces";
declare class CandidateBox {
utilities: Utilities;
options: KeyboardOptions;
candidateBoxElement: HTMLDivElement;
pageIndex: number;
pageSize: number;
constructor({ utilities }: CandidateBoxParams);
constructor({ utilities, options }: CandidateBoxParams);
destroy(): void;
show({ candidateValue, targetElement, onSelect, }: CandidateBoxShowParams): void;
renderPage({ candidateListPages, targetElement, pageIndex, nbPages, onItemSelected, }: CandidateBoxRenderParams): void;

View File

@ -1,6 +1,6 @@
/*!
*
* simple-keyboard v3.4.210
* simple-keyboard v3.5.0
* https://github.com/hodgef/simple-keyboard
*
* Copyright (c) Francisco Hodge (https://github.com/hodgef) and project contributors.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -17,6 +17,7 @@ export interface KeyboardInput {
}
export type CandidateBoxParams = {
utilities: Utilities;
options: KeyboardOptions;
};
export type CandidateBoxShowParams = {
candidateValue: string;

View File

@ -1,6 +1,6 @@
{
"name": "simple-keyboard",
"version": "3.4.210",
"version": "3.5.0",
"description": "On-screen Javascript Virtual Keyboard",
"main": "build/index.js",
"scripts": {

View File

@ -5,16 +5,19 @@ import {
CandidateBoxParams,
CandidateBoxRenderParams,
CandidateBoxShowParams,
KeyboardOptions,
} from "./../interfaces";
class CandidateBox {
utilities: Utilities;
options: KeyboardOptions;
candidateBoxElement!: HTMLDivElement;
pageIndex = 0;
pageSize;
constructor({ utilities }: CandidateBoxParams) {
constructor({ utilities, options }: CandidateBoxParams) {
this.utilities = utilities;
this.options = options;
Utilities.bindMethods(CandidateBox, this);
this.pageSize = this.utilities.getOptions().layoutCandidatesPageSize || 5;
}
@ -82,7 +85,7 @@ class CandidateBox {
};
candidateListLIElement.className = "hg-candidate-box-list-item";
candidateListLIElement.textContent = candidateListItem;
candidateListLIElement.textContent = this.options.display?.[candidateListItem] || candidateListItem;
candidateListLIElement.onclick = (e = getMouseEvent()) =>
onItemSelected(candidateListItem, e);

View File

@ -215,6 +215,7 @@ class SimpleKeyboard {
this.candidateBox = this.options.enableLayoutCandidates
? new CandidateBox({
utilities: this.utilities,
options: this.options,
})
: null;
@ -878,6 +879,7 @@ class SimpleKeyboard {
this.candidateBox.destroy();
this.candidateBox = new CandidateBox({
utilities: this.utilities,
options: this.options,
});
}
}

View File

@ -22,7 +22,8 @@ export interface KeyboardInput {
}
export type CandidateBoxParams = {
utilities: Utilities
utilities: Utilities,
options: KeyboardOptions
}
export type CandidateBoxShowParams = {