@progressive-development/pd-forms 0.1.40 → 0.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/PdInput.js +11 -1
- package/stories/input.stories.js +7 -0
package/package.json
CHANGED
package/src/PdInput.js
CHANGED
|
@@ -9,6 +9,7 @@ import '@progressive-development/pd-icon/pd-icon.js';
|
|
|
9
9
|
import { INPUT_TYPE_TEXT } from './PdBaseUiInput.js';
|
|
10
10
|
import { PdBaseInputElement } from './PdBaseInputElement.js';
|
|
11
11
|
|
|
12
|
+
const onlyContainsNumbers = (str) => /^\d+$/.test(str);
|
|
12
13
|
|
|
13
14
|
// https://github.com/Victor-Bernabe/lit-input
|
|
14
15
|
// https://levelup.gitconnected.com/build-a-material-like-input-web-component-using-litelement-20e9e0d203b6
|
|
@@ -69,7 +70,8 @@ export class PdInput extends PdBaseInputElement {
|
|
|
69
70
|
icon: { type: String },
|
|
70
71
|
secret: { type: Boolean }, // True for type password
|
|
71
72
|
minlength: { type: String },
|
|
72
|
-
maxlength: { type: String }, // max length for field
|
|
73
|
+
maxlength: { type: String }, // max length for field,
|
|
74
|
+
onlyNumbers: { type: Boolean }, // if only numbers allowed
|
|
73
75
|
};
|
|
74
76
|
}
|
|
75
77
|
|
|
@@ -104,6 +106,14 @@ export class PdInput extends PdBaseInputElement {
|
|
|
104
106
|
`;
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
_onKeyUp() {
|
|
110
|
+
if (this.onlyNumbers && !onlyContainsNumbers(this._input.value)) {
|
|
111
|
+
this._input.value = this._input.value.replace(/\D/g, '')
|
|
112
|
+
} else {
|
|
113
|
+
super._onKeyUp();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
107
117
|
}
|
|
108
118
|
|
|
109
119
|
|
package/stories/input.stories.js
CHANGED
|
@@ -66,6 +66,13 @@ function Template({
|
|
|
66
66
|
placeHolder="Placeholder Text"
|
|
67
67
|
></pd-input>
|
|
68
68
|
|
|
69
|
+
<h3>Default Input only Numbers</h3>
|
|
70
|
+
<pd-input
|
|
71
|
+
id="test2Id"
|
|
72
|
+
onlyNumbers
|
|
73
|
+
placeHolder="Placeholder Text"
|
|
74
|
+
></pd-input>
|
|
75
|
+
|
|
69
76
|
<h3>Default Input with value</h3>
|
|
70
77
|
<pd-input
|
|
71
78
|
id="test3Id"
|