Skip to content

fix(ui5-multiinput): hide placeholder when tokens #2789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/main/src/Input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
?disabled="{{disabled}}"
?readonly="{{_readonly}}"
.value="{{value}}"
placeholder="{{placeholder}}"
placeholder="{{_placeholder}}"
maxlength="{{maxlength}}"
role="{{accInfo.input.role}}"
aria-owns="{{accInfo.input.ariaOwns}}"
Expand Down
8 changes: 8 additions & 0 deletions packages/main/src/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,14 @@ class Input extends UI5Element {
return isPhone();
}

/**
* Returns the placeholder value.
* @protected
*/
get _placeholder() {
return this.placeholder;
}

/**
* Returns the caret position inside the native input
* @protected
Expand Down
12 changes: 12 additions & 0 deletions packages/main/src/MultiInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ class MultiInput extends Input {
return `${this._id}-hiddenText-nMore`;
}

/**
* Returns the placeholder value when there are no tokens.
* @protected
*/
get _placeholder() {
if (this.tokenizer && this.tokenizer._tokens.length) {
return "";
}

return this.placeholder;
}

get accInfo() {
const ariaDescribedBy = `${this._tokensCountTextId} ${this.suggestionsTextId} ${this.valueStateTextId} ${this.suggestionsCount}`.trim();
return {
Expand Down
6 changes: 3 additions & 3 deletions packages/main/test/pages/MultiInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<h1>Basic API</h1>

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

<br>
<br>
Expand Down Expand Up @@ -278,8 +278,8 @@ <h1>Test value-help-trigger with F4 and Alt + ArrowUp/Down</h1>
</div>

<div>
<ui5-title>MultiInput with tokesn with custom icon</ui5-title>
<ui5-multi-input style="width: 500px;">
<ui5-title>MultiInput with tokens with custom icon</ui5-title>
<ui5-multi-input id="mi-with-tokens-customicon" placeholder="Placeholder" style="width: 500px;">
<ui5-token slot="tokens" text="Menu">
<ui5-icon name="menu" accessible-name="Menu here" slot="closeIcon"></ui5-icon>
</ui5-token>
Expand Down
18 changes: 13 additions & 5 deletions packages/main/test/specs/MultiInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getTokenizerPopoverId = (inputId) => {
return browser.execute(async (inputId) => {
const input = await document.querySelector(`#${inputId}`);
const staticAreaItem = await (input.shadowRoot.querySelector("ui5-tokenizer").getStaticAreaItemDomRef());

return staticAreaItem.host.classList[0];
}, inputId);
}
Expand All @@ -22,19 +22,19 @@ describe("MultiInput general interaction", () => {

assert.ok(!basicTokenizer.getProperty("expanded"), "Tokenizer should not be expanded");
});

it ("tests opening of tokenizer Popover", () => {
const tokenizer = $("#basic-overflow").shadow$("ui5-tokenizer");
const nMoreLabel = tokenizer.shadow$(".ui5-tokenizer-more-text");

nMoreLabel.click();

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

assert.ok(rpo.getProperty("opened"), "More Popover should be open");
});

it ("fires value-help-trigger on icon press", () => {
const label = $("#basic-event-listener");
const icon = $("#basic-overflow-and-icon").shadow$("ui5-icon");
Expand All @@ -47,7 +47,7 @@ describe("MultiInput general interaction", () => {

// assert
assert.strictEqual(label.getText(), EXPECTED_TEXT, "value help press event is fired");

});

it ("fires value-help-trigger with F4 and Alt/Option + ArrowUp/Down", () => {
Expand Down Expand Up @@ -123,6 +123,14 @@ describe("MultiInput general interaction", () => {
assert.ok(!popover.getProperty("opened"), "Suggestion Popovoer is closed");
assert.strictEqual(mi.$$("ui5-token").length, 1, "a token is added after selection");
});

it ("Placeholder", () => {
const mi1 = browser.$("#empty-mi").shadow$(".ui5-input-inner");
const mi2 = browser.$("#mi-with-tokens-customicon").shadow$(".ui5-input-inner");

assert.strictEqual(mi1.getAttribute("placeholder"), "Placeholder", "a token is added after selection");
assert.strictEqual(mi2.getAttribute("placeholder"), "", "a token is added after selection");
});
});

describe("ARIA attributes", () => {
Expand Down