Skip to content

Commit

Permalink
Set placeholder after select input was rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
SweetDealer committed Aug 23, 2024
1 parent aaa87c1 commit bd335fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elsci-io/ui-essential",
"version": "1.0.67",
"version": "1.0.68",
"description": "Material Design components created for products built by elsci.io",
"main": "src/index.js",
"type": "module",
Expand Down
7 changes: 6 additions & 1 deletion src/SelectInput/SelectInput.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {KeyCode, safeHtml} from "../utils.js";
import {KeyCode} from "../utils.js";

export default class SelectInput extends HTMLElement {
#inputElement;
Expand Down Expand Up @@ -35,6 +35,11 @@ export default class SelectInput extends HTMLElement {
this.#inputElement.setDisabled(isDisabled);
}

/** @param {string} placeholderText */
setPlaceholder(placeholderText){
this.#inputElement.setPlaceholder(placeholderText);
}

showDropdown() {
this.#dropdownElement.show();
this.#callbacks.onShowDropdown.forEach(callback => callback());
Expand Down
8 changes: 7 additions & 1 deletion src/TextInput/TextInput.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import TextInputValidityState from "./TextInputValidityState.js";
import {isFiniteNumber, KeyCode, safeHtml} from "../utils.js"
import {isFiniteNumber, KeyCode, safeHtml, safeText} from "../utils.js"

/**
* @typedef {import("../InputValidator.js").default} InputValidator
Expand Down Expand Up @@ -129,6 +129,12 @@ export default class TextInput extends HTMLElement {
this.#inputElement.toggleAttribute("disabled", isDisabled);
}

/** @param {string} placeholderText */
setPlaceholder(placeholderText){
this.#inputElement.setAttribute('placeholder', safeText(placeholderText));
this.classList.add("placeholder-shown");
}

/** @param {KeyboardEvent} event */
#onKeyDown(event) {
if (this.#inputElement.type === "number" && (event.key === KeyCode.Up || event.key === KeyCode.Down))
Expand Down

0 comments on commit bd335fb

Please sign in to comment.