Skip to content

Commit c149f5f

Browse files
ivoplashkovfifoosid
authored andcommitted
feat(ui5-input): introduce maxlength property (#976)
1 parent e53a76d commit c149f5f

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

packages/main/src/Input.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
?required="{{required}}"
1414
.value="{{value}}"
1515
placeholder="{{placeholder}}"
16+
maxlength="{{maxlength}}"
1617
role="{{accInfo.input.role}}"
1718
aria-owns="{{accInfo.input.ariaOwns}}"
1819
aria-invalid="{{accInfo.input.ariaInvalid}}"

packages/main/src/Input.js

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
isSpace,
1010
isEnter,
1111
} from "@ui5/webcomponents-base/dist/events/PseudoEvents.js";
12+
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
1213
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
1314
// import Icon from "./Icon.js";
1415
import InputType from "./types/InputType.js";
@@ -210,6 +211,17 @@ const metadata = {
210211
type: Boolean,
211212
},
212213

214+
/**
215+
* Sets the maximum number of characters available in the input field.
216+
*
217+
* @type {Integer}
218+
* @since 1.0.0-rc.5
219+
* @public
220+
*/
221+
maxlength: {
222+
type: Integer,
223+
},
224+
213225
/**
214226
* @private
215227
*/

packages/main/test/pages/Input.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h3> Input type 'Email'</h3>
7777
<ui5-input id="myInput4" style="width:100%" type="Email" name="my-input-email"></ui5-input>
7878

7979
<h3> Input type 'Tel'</h3>
80-
<ui5-input id="myInput5" style="width:100%" type="Tel" name="my-input-tel"></ui5-input>
80+
<ui5-input id="myInput5" maxlength="10" style="width:100%" type="Tel" name="my-input-tel"></ui5-input>
8181

8282
<h3> Input type 'URL'</h3>
8383
<ui5-input id="myInput6" style="width:100%" type="URL"></ui5-input>

packages/main/test/specs/Input.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,19 @@ describe("Input general interaction", () => {
129129
assert.strictEqual(innerInput.getValue(), "", "Inner's property value should be empty");
130130
});
131131
*/
132+
133+
it("Input's maxlength property is set correctly", () => {
134+
const input5 = $("#myInput5");
135+
const inputShadowRef = $("#myInput5").shadow$("input");
136+
137+
inputShadowRef.click();
138+
139+
for (let i = 0; i <15 ; i++) {
140+
inputShadowRef.keys("c");
141+
}
142+
143+
assert.strictEqual(inputShadowRef.getProperty("value").length, 10, "Input's value should not exceed 10 characters.");
144+
assert.ok(input5.getProperty("maxlength"), "Input's maxlength property should be applied.");
145+
assert.strictEqual(inputShadowRef.getAttribute("maxlength"), "10", "Input's maxlength attribute should be applied.");
146+
});
132147
});

0 commit comments

Comments
 (0)