mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Add rules to eslint to better match our coding conventions.
Summary: We used tslint earlier, and on switching to eslint, some rules were not transfered. This moves more rules over, for consistent conventions or helpful warnings. - Name private members with a leading underscore. - Prefer interface over a type alias. - Use consistent spacing around ':' in type annotations. - Use consistent spacing around braces of code blocks. - Use semicolons consistently at the ends of statements. - Use braces around even one-liner blocks, like conditionals and loops. - Warn about shadowed variables. Test Plan: Fixed all new warnings. Should be no behavior changes in code. Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2831
This commit is contained in:
@@ -55,18 +55,18 @@ export class Autocomplete<Item extends ACItem> extends Disposable {
|
||||
|
||||
constructor(
|
||||
private _triggerElem: HTMLInputElement | HTMLTextAreaElement,
|
||||
private readonly options: IAutocompleteOptions<Item>,
|
||||
private readonly _options: IAutocompleteOptions<Item>,
|
||||
) {
|
||||
super();
|
||||
|
||||
const content = cssMenuWrap(
|
||||
this._menuContent = cssMenu({class: options.menuCssClass || ''},
|
||||
dom.forEach(this._items, (item) => options.renderItem(item, this._highlightFunc)),
|
||||
this._menuContent = cssMenu({class: _options.menuCssClass || ''},
|
||||
dom.forEach(this._items, (item) => _options.renderItem(item, this._highlightFunc)),
|
||||
dom.style('min-width', _triggerElem.getBoundingClientRect().width + 'px'),
|
||||
dom.on('mouseleave', (ev) => this._setSelected(-1, true)),
|
||||
dom.on('click', (ev) => {
|
||||
this._setSelected(this._findTargetItem(ev.target), true);
|
||||
if (options.onClick) { options.onClick(); }
|
||||
if (_options.onClick) { _options.onClick(); }
|
||||
})
|
||||
),
|
||||
// Prevent trigger element from being blurred on click.
|
||||
@@ -91,7 +91,7 @@ export class Autocomplete<Item extends ACItem> extends Disposable {
|
||||
this.onDispose(() => { dom.domDispose(content); content.remove(); });
|
||||
|
||||
// Prepare and create the Popper instance, which places the content according to the options.
|
||||
const popperOptions = merge({}, defaultPopperOptions, options.popperOptions);
|
||||
const popperOptions = merge({}, defaultPopperOptions, _options.popperOptions);
|
||||
this._popper = createPopper(_triggerElem, content, popperOptions);
|
||||
this.onDispose(() => this._popper.destroy());
|
||||
}
|
||||
@@ -110,7 +110,7 @@ export class Autocomplete<Item extends ACItem> extends Disposable {
|
||||
const elem = (this._menuContent.children[index] as HTMLElement) || null;
|
||||
const prev = this._selected;
|
||||
if (elem !== prev) {
|
||||
const clsName = this.options.selectedCssClass || 'selected';
|
||||
const clsName = this._options.selectedCssClass || 'selected';
|
||||
if (prev) { prev.classList.remove(clsName); }
|
||||
if (elem) {
|
||||
elem.classList.add(clsName);
|
||||
@@ -123,7 +123,7 @@ export class Autocomplete<Item extends ACItem> extends Disposable {
|
||||
if (updateValue) {
|
||||
// Update trigger's value with the selected choice, or else with the last typed value.
|
||||
if (elem) {
|
||||
this._triggerElem.value = this.options.getItemText(this.getSelectedItem()!);
|
||||
this._triggerElem.value = this._options.getItemText(this.getSelectedItem()!);
|
||||
} else {
|
||||
this._triggerElem.value = this._lastAsTyped;
|
||||
}
|
||||
@@ -147,7 +147,7 @@ export class Autocomplete<Item extends ACItem> extends Disposable {
|
||||
this._lastAsTyped = inputVal;
|
||||
// TODO We should perhaps debounce the search() call in some clever way, to avoid unnecessary
|
||||
// searches while typing. Today, search() is synchronous in practice, so it doesn't matter.
|
||||
const acResults = await this.options.search(inputVal);
|
||||
const acResults = await this._options.search(inputVal);
|
||||
this._highlightFunc = acResults.highlightFunc;
|
||||
this._items.set(acResults.items);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user