Skip to content

Commit bd1bd6e

Browse files
authored
fix(ui5-input): enable centering of text (#2788)
1 parent 5fc108d commit bd1bd6e

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

packages/main/src/Input.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<input id="{{_id}}-inner"
1010
class="ui5-input-inner"
11+
style="{{styles.innerInput}}"
1112
type="{{inputType}}"
1213
inner-input
1314
?inner-input-with-icon="{{icon.length}}"

packages/main/src/Input.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,11 @@ class Input extends UI5Element {
939939
* @protected
940940
*/
941941
get nativeInput() {
942-
return this.getDomRef().querySelector(`input`);
942+
return this.getDomRef() && this.getDomRef().querySelector(`input`);
943+
}
944+
945+
get nativeInputWidth() {
946+
return this.nativeInput && this.nativeInput.offsetWidth;
943947
}
944948

945949
getLabelableElementId() {
@@ -1114,6 +1118,9 @@ class Input extends UI5Element {
11141118
suggestionsPopover: {
11151119
"max-width": `${this._inputWidth}px`,
11161120
},
1121+
innerInput: {
1122+
padding: this.nativeInputWidth < 48 ? "0" : undefined,
1123+
},
11171124
};
11181125
}
11191126

packages/main/src/themes/DatePicker.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
:host .ui5-date-picker-input {
1717
width: 100%;
18-
min-width: inherit;
18+
min-width: 12.5625rem;
1919
color: inherit;
2020
background-color: inherit;
2121
line-height: inherit;

packages/main/src/themes/Input.css

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
line-height: normal;
2020
letter-spacing: normal;
2121
word-spacing: normal;
22+
text-align: start;
2223
}
2324

2425
:host([focused]) {
@@ -58,7 +59,9 @@
5859
-moz-appearance: textfield;
5960
padding: var(--_ui5_input_inner_padding);
6061
box-sizing: border-box;
61-
min-width: 3rem;
62+
min-width: inherit;
63+
width: 100%;
64+
text-align: inherit;
6265
text-overflow: ellipsis;
6366
flex: 1;
6467
outline: none;

packages/main/test/pages/Input.html

+10
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@ <h3>Input in a Dialog</h3>
307307
</ui5-input>
308308
</ui5-dialog>
309309

310+
<h3>Short Input With Centered Text</h3>
311+
<ui5-input class="short" value="244"></ui5-input>
312+
<style>
313+
.short {
314+
width: 2.5rem;
315+
min-width: 2.5rem;
316+
text-align: center;
317+
}
318+
</style>
319+
310320
<script>
311321
btnOpenDialog.addEventListener("click", function () {
312322
dialog.open();

0 commit comments

Comments
 (0)