diff --git a/.changeset/giant-ties-attack.md b/.changeset/giant-ties-attack.md new file mode 100644 index 000000000..90505cd6b --- /dev/null +++ b/.changeset/giant-ties-attack.md @@ -0,0 +1,8 @@ +--- +'@lion/ui': patch +--- + +feat(LionInputStepper): implement self-destructing output content for value display + +1. from
${this.__valueText}
to ${this.\_\_valueText} +2. remove the \_onEnterButton() and \_onLeaveButton() logic. diff --git a/packages/ui/components/input-stepper/src/LionInputStepper.js b/packages/ui/components/input-stepper/src/LionInputStepper.js index 89f8c7531..3c70063bc 100644 --- a/packages/ui/components/input-stepper/src/LionInputStepper.js +++ b/packages/ui/components/input-stepper/src/LionInputStepper.js @@ -1,4 +1,4 @@ -import { html, css, render } from 'lit'; +import { html, css, render, nothing } from 'lit'; import { formatNumber, LocalizeMixin, parseNumber } from '@lion/ui/localize-no-side-effects.js'; import { LionInput } from '@lion/ui/input.js'; import { IsNumber, MinNumber, MaxNumber } from '@lion/ui/form-core.js'; @@ -96,8 +96,6 @@ export class LionInputStepper extends LocalizeMixin(LionInput) { this._increment = this._increment.bind(this); this._decrement = this._decrement.bind(this); - this._onEnterButton = this._onEnterButton.bind(this); - this._onLeaveButton = this._onLeaveButton.bind(this); } connectedCallback() { @@ -244,6 +242,26 @@ export class LionInputStepper extends LocalizeMixin(LionInput) { this._inputNode.removeAttribute('aria-valuenow'); this._inputNode.removeAttribute('aria-valuetext'); } + this._destroyOutputContent(); + } + + _destroyOutputContent() { + const outputElement = /** @type {HTMLElement} */ ( + this.shadowRoot?.querySelector('.input-stepper__value') + ); + + const timeoutValue = outputElement?.dataset?.selfDestruct + ? Number(outputElement.dataset.selfDestruct) + : 2000; + clearTimeout(this.timer); + if (outputElement) { + this.timer = setTimeout(() => { + if (outputElement.parentNode) { + this.__valueText = nothing; + this.requestUpdate(); + } + }, timeoutValue); + } } /** @@ -394,8 +412,6 @@ export class LionInputStepper extends LocalizeMixin(LionInput) {