Skip to content

Commit

Permalink
change max/min value of input
Browse files Browse the repository at this point in the history
  • Loading branch information
SweetDealer committed Feb 12, 2024
1 parent 5dcf706 commit 033978f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
17 changes: 14 additions & 3 deletions src/EditText/EditText.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export default class EditText extends HTMLElement {
this.#updatePopupPosition();
this.#children.popup.showModal();
this.#children.input.focus();
this.#setInputWidth(this.#children.input, this.#children.input.rawValue);
}

#onInput(_, isValid) {
Expand Down Expand Up @@ -154,7 +153,10 @@ export default class EditText extends HTMLElement {
let {top, left} = this.getBoundingClientRect();
this.#children.popup.style.top = top + window.scrollY + "px";
this.#children.popup.style.left = left + window.scrollX + "px";
this.#children.popup.style['max-width'] = this.offsetWidth + 16 + "px";
if (!this.hasAttribute('max-width')) {
this.#setInputWidth(this.#children.input, this.#children.input.rawValue);
this.#children.popup.style['max-width'] = Math.max(this.offsetWidth + 16, 128) + "px";
}
}

#isNumberType() {
Expand All @@ -163,14 +165,23 @@ export default class EditText extends HTMLElement {

#setInputWidth(element, text){
const textWidth = getTextWidth(text)
element.style.width = textWidth + 16 + "px";
element.style.width = Math.max(112, textWidth) + "px";
}

#initAttributes(){
if (this.hasAttribute("suffix"))
this.#suffix = this.getAttribute("suffix");
if (this.hasAttribute("prefix"))
this.#prefix = this.getAttribute("prefix");
if (this.hasAttribute("max-width")) {
this.#children.popup.style['max-width'] = this.getAttribute("max-width") + 'px';
this.#children.input.style['max-width'] = this.getAttribute("max-width") - 1 + 'px';
}
if (this.hasAttribute("min-width")) {
this.#children.popup.style['min-width'] = this.getAttribute("min-width") + 'px';
this.#children.input.style['min-width'] = this.getAttribute("min-width") - 1 + 'px';
}

this.#children.input.value = this.#getValueAttr();
if(this.hasAttribute("scale"))
this.displayTextTransformer = (text) => roundToDecimalPlaces(text, parseInt(this.getAttribute("scale")));
Expand Down
17 changes: 9 additions & 8 deletions src/EditText/EditText.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ edit-text {
}

.edit-text__popup {
max-width: 100%;
box-shadow: var(--box-shadow);
position: absolute;
padding: 0;
padding: .5rem .5rem 1rem;
border: none;
margin: -0.7rem 0 0 -0.75rem;
min-width: 4rem;
min-width: 8rem;
}

.edit-text__popup text-input {
padding: .5rem .5rem 1rem;
min-width: 4rem;
width: 100%;
padding-top: 0;
}

.edit-text__popup text-input input{
width: 11ch;
}
//.edit-text__popup text-input input{
// width: 11ch;
//}

.edit-text__popup .text-input__error {
height: unset;
Expand All @@ -31,7 +32,7 @@ edit-text {

.edit-text__popup .text-input--with-right-icon .text-input__input {
padding-right: 0;
width: inherit;
//width: inherit;
}

edit-text .edit-text__text {
Expand Down

0 comments on commit 033978f

Please sign in to comment.