Extend Foundry's MultiSelectElement so that I can provide a label to it

This commit is contained in:
Oliver-Akins 2025-04-27 20:46:55 -06:00
parent 5e9b91b199
commit d858aa5b66
5 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,21 @@
const { HTMLMultiSelectElement } = foundry.applications.elements;
export class CustomMultiSelect extends HTMLMultiSelectElement {
static tagName = `stats-tracker-multi-select`;
get placeholder() {
return this.getAttribute(`placeholder`);
};
_buildElements() {
const [ tags, select ] = super._buildElements();
const label = document.createElement(`div`);
label.ariaHidden = true;
label.innerHTML = game.i18n.localize(this.placeholder);
select.ariaLabel = game.i18n.localize(this.placeholder);
return [ label, tags, select ];
};
};

View file

@ -0,0 +1,19 @@
import { CustomMultiSelect } from "./CustomMultiSelect.mjs";
import { Logger } from "../../utils/Logger.mjs";
const components = [
CustomMultiSelect,
];
export function registerCustomComponents() {
(CONFIG.CACHE ??= {}).componentListeners ??= [];
for (const component of components) {
if (!window.customElements.get(component.tagName)) {
Logger.debug(`Registering component "${component.tagName}"`);
window.customElements.define(
component.tagName,
component,
);
};
}
};