Skip to content

Commit 679dae3

Browse files
authored
fix(ui5-multiinput): hide placeholder when tokens (#2789)
Fixes: #2261
1 parent d6a7b81 commit 679dae3

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

packages/main/src/Input.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
?disabled="{{disabled}}"
1515
?readonly="{{_readonly}}"
1616
.value="{{value}}"
17-
placeholder="{{placeholder}}"
17+
placeholder="{{_placeholder}}"
1818
maxlength="{{maxlength}}"
1919
role="{{accInfo.input.role}}"
2020
aria-owns="{{accInfo.input.ariaOwns}}"

packages/main/src/Input.js

+8
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,14 @@ class Input extends UI5Element {
11761176
return isPhone();
11771177
}
11781178

1179+
/**
1180+
* Returns the placeholder value.
1181+
* @protected
1182+
*/
1183+
get _placeholder() {
1184+
return this.placeholder;
1185+
}
1186+
11791187
/**
11801188
* Returns the caret position inside the native input
11811189
* @protected

packages/main/src/MultiInput.js

+12
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ class MultiInput extends Input {
278278
return `${this._id}-hiddenText-nMore`;
279279
}
280280

281+
/**
282+
* Returns the placeholder value when there are no tokens.
283+
* @protected
284+
*/
285+
get _placeholder() {
286+
if (this.tokenizer && this.tokenizer._tokens.length) {
287+
return "";
288+
}
289+
290+
return this.placeholder;
291+
}
292+
281293
get accInfo() {
282294
const ariaDescribedBy = `${this._tokensCountTextId} ${this.suggestionsTextId} ${this.valueStateTextId} ${this.suggestionsCount}`.trim();
283295
return {

packages/main/test/pages/MultiInput.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<h1>Basic API</h1>
5555

5656
<h1 class="sample-container-title">Empty Multi Input</h1>
57-
<ui5-multi-input></ui5-multi-input>
57+
<ui5-multi-input id="empty-mi" placeholder="Placeholder"></ui5-multi-input>
5858

5959
<br>
6060
<br>
@@ -278,8 +278,8 @@ <h1>Test value-help-trigger with F4 and Alt + ArrowUp/Down</h1>
278278
</div>
279279

280280
<div>
281-
<ui5-title>MultiInput with tokesn with custom icon</ui5-title>
282-
<ui5-multi-input style="width: 500px;">
281+
<ui5-title>MultiInput with tokens with custom icon</ui5-title>
282+
<ui5-multi-input id="mi-with-tokens-customicon" placeholder="Placeholder" style="width: 500px;">
283283
<ui5-token slot="tokens" text="Menu">
284284
<ui5-icon name="menu" accessible-name="Menu here" slot="closeIcon"></ui5-icon>
285285
</ui5-token>

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

+13-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const getTokenizerPopoverId = (inputId) => {
44
return browser.execute(async (inputId) => {
55
const input = await document.querySelector(`#${inputId}`);
66
const staticAreaItem = await (input.shadowRoot.querySelector("ui5-tokenizer").getStaticAreaItemDomRef());
7-
7+
88
return staticAreaItem.host.classList[0];
99
}, inputId);
1010
}
@@ -22,19 +22,19 @@ describe("MultiInput general interaction", () => {
2222

2323
assert.ok(!basicTokenizer.getProperty("expanded"), "Tokenizer should not be expanded");
2424
});
25-
25+
2626
it ("tests opening of tokenizer Popover", () => {
2727
const tokenizer = $("#basic-overflow").shadow$("ui5-tokenizer");
2828
const nMoreLabel = tokenizer.shadow$(".ui5-tokenizer-more-text");
29-
29+
3030
nMoreLabel.click();
3131

3232
const rpoClassName = getTokenizerPopoverId("basic-overflow");
3333
const rpo = $(`.${rpoClassName}`).shadow$("ui5-responsive-popover");
3434

3535
assert.ok(rpo.getProperty("opened"), "More Popover should be open");
3636
});
37-
37+
3838
it ("fires value-help-trigger on icon press", () => {
3939
const label = $("#basic-event-listener");
4040
const icon = $("#basic-overflow-and-icon").shadow$("ui5-icon");
@@ -47,7 +47,7 @@ describe("MultiInput general interaction", () => {
4747

4848
// assert
4949
assert.strictEqual(label.getText(), EXPECTED_TEXT, "value help press event is fired");
50-
50+
5151
});
5252

5353
it ("fires value-help-trigger with F4 and Alt/Option + ArrowUp/Down", () => {
@@ -123,6 +123,14 @@ describe("MultiInput general interaction", () => {
123123
assert.ok(!popover.getProperty("opened"), "Suggestion Popovoer is closed");
124124
assert.strictEqual(mi.$$("ui5-token").length, 1, "a token is added after selection");
125125
});
126+
127+
it ("Placeholder", () => {
128+
const mi1 = browser.$("#empty-mi").shadow$(".ui5-input-inner");
129+
const mi2 = browser.$("#mi-with-tokens-customicon").shadow$(".ui5-input-inner");
130+
131+
assert.strictEqual(mi1.getAttribute("placeholder"), "Placeholder", "a token is added after selection");
132+
assert.strictEqual(mi2.getAttribute("placeholder"), "", "a token is added after selection");
133+
});
126134
});
127135

128136
describe("ARIA attributes", () => {

0 commit comments

Comments
 (0)