<commit_before>import {BaseListBox} from "./BaseListBox";
import {ListboxSettings} from "./contract/ListboxSettings";
import {ListboxItem} from "./contract/ListboxItem";

export class SingleSelectListbox extends BaseListBox {

    private _selectedDomItem: HTMLElement;

    /**
     * Create an instance of SingleSelectListbox.
     *
     * Inherit a {Listbox} class.
     *
     * @constructor
     * @this {SingleSelectListbox}
     * @param {object} domElement DOM element to be converted to the Listbox
     * @param {object} options an object with Listbox settings
     */
    constructor(domElement: HTMLElement, options: ListboxSettings) {
        super(domElement, options);
        this._selectedDomItem = null;
        this.createListbox();
    }

    /**
     * Reset all items and select a given one.
     *
     * @this {SingleSelectListbox}
     * @param {object} domItem a DOM object
     */
    public onItemClick(domItem: HTMLElement): void {
        if (domItem.classList.contains(BaseListBox.LIST_ITEM_CLASS_DISABLED) ||
            domItem.classList.contains(BaseListBox.LIST_ITEM_CLASS_GROUP)) {
            return;
        }

        if (this._selectedDomItem) {
            this.clearSelection();
            this._selectedDomItem = null;
        }

        domItem.classList.toggle(BaseListBox.LIST_ITEM_CLASS_SELECTED);
        domItem.focus();
        this._selectedDomItem = domItem;

        const dataItem: ListboxItem = this.getDataItem(domItem.id);
        dataItem.selected = true;
        this.selectedDataItems.push(dataItem);

        this.fireEvent(BaseListBox.EVENT_VALUE_CHANGED, this.getDataItem(domItem.id));
    }


    /**
     * Select first visible item if none selected.
     *
     * @this {SingleSelectListbox}
     */
    public onFilterChange(): void {
        if (!this._selectedDomItem || this._selectedDomItem.querySelectorAll(":visible").length > 0) {
            const element: HTMLElement = this._list.querySelectorAll(':visible').item(0) as HTMLElement;
            if (element && (element as any).length > 0) { // TODO
                this.onItemClick(element);
            }
        }

        this.fireEvent(BaseListBox.EVENT_FILTER_CHANGED, this._searchbar.value);
    }
}<commit_msg>fixed old :visible selector<commit_after>import {BaseListBox} from "./BaseListBox";
import {ListboxSettings} from "./contract/ListboxSettings";
import {ListboxItem} from "./contract/ListboxItem";

export class SingleSelectListbox extends BaseListBox {

    private _selectedDomItem: HTMLElement;

    /**
     * Create an instance of SingleSelectListbox.
     *
     * Inherit a {Listbox} class.
     *
     * @constructor
     * @this {SingleSelectListbox}
     * @param {object} domElement DOM element to be converted to the Listbox
     * @param {object} options an object with Listbox settings
     */
    constructor(domElement: HTMLElement, options: ListboxSettings) {
        super(domElement, options);
        this._selectedDomItem = null;
        this.createListbox();
    }

    /**
     * Reset all items and select a given one.
     *
     * @this {SingleSelectListbox}
     * @param {object} domItem a DOM object
     */
    public onItemClick(domItem: HTMLElement): void {
        if (domItem.classList.contains(BaseListBox.LIST_ITEM_CLASS_DISABLED) ||
            domItem.classList.contains(BaseListBox.LIST_ITEM_CLASS_GROUP)) {
            return;
        }

        if (this._selectedDomItem) {
            this.clearSelection();
            this._selectedDomItem = null;
        }

        domItem.classList.toggle(BaseListBox.LIST_ITEM_CLASS_SELECTED);
        domItem.focus();
        this._selectedDomItem = domItem;

        const dataItem: ListboxItem = this.getDataItem(domItem.id);
        dataItem.selected = true;
        this.selectedDataItems.push(dataItem);

        this.fireEvent(BaseListBox.EVENT_VALUE_CHANGED, this.getDataItem(domItem.id));
    }


    /**
     * Select first visible item if none selected.
     *
     * @this {SingleSelectListbox}
     */
    public onFilterChange(): void {
        if (!this._selectedDomItem || this._selectedDomItem.style.display === "none") {
            const elements: NodeListOf<Element> = this._list.querySelectorAll("." + BaseListBox.LIST_ITEM_CLASS);
            for (let i: number = 0; i < elements.length; i++) {
                let element: HTMLElement = elements.item(i) as HTMLElement;
                if (!element.classList.contains(BaseListBox.LIST_ITEM_CLASS_GROUP) &&
                    !element.classList.contains(BaseListBox.LIST_ITEM_CLASS_DISABLED) &&
                    element.style.display !== "none") {
                    this.onItemClick(element);
                    break;
                }
            }
        }

        this.fireEvent(BaseListBox.EVENT_FILTER_CHANGED, this._searchbar.value);
    }
}
{'fraction_non_alphanumeric': 0.10403790688092295, 'fraction_numerical': 0.0008240626287597857, 'mean_word_length': 2.528343023255814, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7633834', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1378, 'n_words': 283}