Skip to content

Commit 85e3799

Browse files
authored
Merge pull request #5 from keithclark/dev
2 parents 2485e6c + fde8faa commit 85e3799

File tree

6 files changed

+19
-24
lines changed

6 files changed

+19
-24
lines changed

dist/richinput.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ declare module "@keithclark/richinput" {
104104
readonly willValidate: boolean;
105105
/**
106106
* The regular expression pattern used to control styling of the input
107-
* value. The pattern must match the entire input value, rather than
108-
* matching a substring.
107+
* value. It's compiled with the `v` flag, so it's Unicode-aware. The
108+
* pattern must match the entire input value—not just part of it.
109109
*/
110110
stylePattern: string;
111111
/**

dist/richinput.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@keithclark/richinput",
33
"description": "A web component for more colourful text inputs",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"main": "dist/richinput.js",
66
"files": ["dist/"],
77
"types": "./dist/richinput.d.ts",

src/RichInputElement.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export default class RichInputElement extends HTMLElement {
5454
classList.toggle('noselection', selectionStart !== null && selectionStart === selectionEnd);
5555
};
5656

57-
// when receiving focus update the ::selection styles
5857
this.addEventListener('focus', () => {
5958
// when receiving focus update the ::selection styles
6059
this.#updateSelectionStyles();
@@ -101,7 +100,7 @@ export default class RichInputElement extends HTMLElement {
101100
attributeChangedCallback(name, oldValue, newValue) {
102101
if (name === 'stylepattern') {
103102
try {
104-
this.#formatRegex = new RegExp(`^(?:${newValue})$`, 'gd');
103+
this.#formatRegex = new RegExp(`^(?:${newValue})$`, 'dv');
105104
} catch (e) {
106105
this.#formatRegex = null;
107106
}
@@ -127,9 +126,9 @@ export default class RichInputElement extends HTMLElement {
127126
}
128127

129128
#updateSelectionStyles() {
130-
// It's not possible for ::selection to inherit values form the cascade
131-
// so we query the host element styles and pass them on through a custom
132-
// property.
129+
// It's not possible for ::selection to inherit values from the cascade
130+
// so we query the host element for its styles and pass them on through a
131+
// custom property.
133132
const { backgroundColor } = getComputedStyle(this, '::selection');
134133
this.#input.style.setProperty('--selection', backgroundColor);
135134
}
@@ -142,8 +141,9 @@ export default class RichInputElement extends HTMLElement {
142141
this.#internals.setFormValue(value);
143142
this.#setValidityFromInput();
144143

145-
// If the output doesn't match the regex then there is no need to higlight
146-
// the content so set `textContent`
144+
// If the output doesn't match the regex pattern there is no need to
145+
// highlight the content. Instead we just set `textContent` on the output
146+
// element and exit.
147147
const match = this.#formatRegex?.exec(value);
148148
if (!match) {
149149
this.#output.textContent = value;
@@ -170,7 +170,6 @@ export default class RichInputElement extends HTMLElement {
170170
chunks.push(htmlEncode(value.slice(lastIndex)));
171171
}
172172
this.#output.innerHTML = chunks.join('');
173-
this.#formatRegex.lastIndex = 0;
174173
}
175174

176175

@@ -416,8 +415,8 @@ export default class RichInputElement extends HTMLElement {
416415

417416
/**
418417
* The regular expression pattern used to control styling of the input value.
419-
* The pattern must match the entire input value, rather than matching a
420-
* substring.
418+
* It's compiled with the `v` flag, so it's Unicode-aware. The pattern must
419+
* match the entire input value—not just part of it.
421420
* @htmlattr stylepattern
422421
* @type {string}
423422
*/

src/styles.css

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
caret-color: fieldtext;
77
background-color: field;
88
line-height: 1;
9-
9+
cursor: text;
1010
}
1111

1212
/** Feature detect Safari */
@@ -31,7 +31,8 @@
3131
outline: auto -webkit-focus-ring-color;
3232
}
3333

34-
:host(:disabled) output {
34+
:host(:disabled) output,
35+
output:empty {
3536
display: none;
3637
}
3738

@@ -59,6 +60,7 @@ div::-webkit-scrollbar {
5960
span {
6061
display: grid;
6162
align-items: center;
63+
flex: 1; /* Ensure the overlay container element always fills the parent */
6264
}
6365

6466
input,output {
@@ -85,12 +87,6 @@ See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply
8587
input.noselection+output {
8688
order:-1
8789
}
88-
/*
89-
input { z-index:1}
90-
*/
91-
output {
92-
pointer-events: none;
93-
}
9490

9591
input {
9692
text-shadow: none;

src/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<div tabindex="-1">
33
<span>
44
<input>
5-
<output aria-hidden="true"></output>
5+
<output inert></output>
66
</span>
77
</div>

0 commit comments

Comments
 (0)