Skip to content

Commit ca0d758

Browse files
committed
input-num: width / selection
1 parent b136d32 commit ca0d758

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ Based on an informal survey and my own repeated frustrations, I came to the conc
272272
- When you use `Shift+Tab` to activate the element, the `<input>` gets the focus. The next `Shift+Tab` activates the outer element. The next one blurs the element.
273273
274274
### HTML Attributes / JavaScript Properties
275-
There are several inverted boolean attributes / properties, where the attribute value is the opposite of the property value. The attribute names all start with `no-`. They are all for turning features off. The default is always attribute = unset / property = `true`. The negative makes sense for the boolean attribute name, but it's clumsy for the property.
275+
There are several inverted boolean attributes / properties, where the attribute value is the opposite of the property value. They are all for turning features off. The negative makes sense for the boolean attribute name, but it's clumsy for the property. The attribute names all start with `no-`. The default is always:
276+
- attribute = unset (null)
277+
- property = `true`
276278
277279
#### DOM Attributes
278280
Property name same as attribute. String as attribute / Number as property.

input-num.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,11 @@ static observedAttributes = [
489489
input = this.#input,
490490
dir = input.selectionDirection,
491491
start = input.selectionStart,
492-
dist = input.selectionEnd - start,
492+
end = input.selectionEnd,
493+
dist = end - start,
493494
val = input.value,
494495
orig = [{num:start, str:val.slice(0, start)},
495-
{num:dist, str:val.slice(start, dist)}];
496+
{num:dist, str:val.slice(start, end)}];
496497
for (obj of orig) {
497498
match = obj.str.match(/[^\d-.eE]/g);
498499
range.push(obj.num - (match ? match.length : 0))
@@ -725,11 +726,11 @@ static observedAttributes = [
725726
else
726727
btns = 0; // no spinning, no confirming = no buttons
727728

728-
if (isWidth || isAlign) {
729+
if (isWidth || isAlign) { // get widths for max, min, units
729730
let txt, type;
730731
style = getComputedStyle(this.#input);
731732
isItalic = (style.fontStyle == "italic");
732-
for (txt of this.#texts) { // units, max, and min
733+
for (txt of this.#texts) {
733734
id = txt.id;
734735
txt.innerHTML = (id == UNITS)
735736
? this.units
@@ -750,7 +751,7 @@ static observedAttributes = [
750751
chars = Math.max(width[MAX], width[MIN]), // text width w/o units
751752
obj = {
752753
[event.blur] : chars + extra - diff,
753-
[event.focus]: chars,
754+
[event.focus]: chars + extra - btns,
754755
[mouse.over] : chars
755756
}
756757
if (isItalic) // right-aligned italics often truncate

0 commit comments

Comments
 (0)