Skip to content
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

fix(ui5-multicombobox): hide placeholder when tokens #2785

Merged
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/MultiComboBox.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<input id="ui5-multi-combobox-input"
.value="{{value}}"
inner-input
placeholder="{{placeholder}}"
placeholder={{_getPlaceholder}}
?disabled={{disabled}}
?readonly={{readonly}}
value-state="{{valueState}}"
Expand Down
8 changes: 8 additions & 0 deletions packages/main/src/MultiComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ class MultiComboBox extends UI5Element {
this.fireSelectionChange();
}

get _getPlaceholder() {
if (this._tokenizer && this._tokenizer.tokens.length) {
return "";
}

return this.placeholder;
}

_handleLeft() {
const cursorPosition = this.getDomRef().querySelector(`input`).selectionStart;

Expand Down
2 changes: 1 addition & 1 deletion packages/main/test/pages/MultiComboBox.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<span>Validating input and placeholder </span>

<br>
<ui5-multi-combobox placeholder="Some initial text">
<ui5-multi-combobox id="mcb-with-placeholder" placeholder="Some initial text">
<ui5-mcb-item selected text="Cosy"></ui5-mcb-item>
<ui5-mcb-item text="Compact"></ui5-mcb-item>
<ui5-mcb-item selected text="Condensed"></ui5-mcb-item>
Expand Down
11 changes: 9 additions & 2 deletions packages/main/test/specs/MultiComboBox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ describe("MultiComboBox general interaction", () => {
});
});

describe("keyboard handling", () => {
describe("General", () => {
browser.url("http://localhost:8080/test-resources/pages/MultiComboBox.html");

it ("tests two-column layout", () => {
const mcb = $("#mcb-two-column-layout");
const staticAreaItemClassName = browser.getStaticAreaItemClassName("#mcb-two-column-layout");
Expand All @@ -236,5 +235,13 @@ describe("MultiComboBox general interaction", () => {
assert.strictEqual(listItem.shadow$(".ui5-li-info").getText(), "DZ", "Additional item text should be displayed");
icon.click();
});

it ("placeholder tests", () => {
const mcb1 = browser.$("#another-mcb").shadow$("#ui5-multi-combobox-input");
const mcb2 = browser.$("#mcb-with-placeholder").shadow$("#ui5-multi-combobox-input");

assert.strictEqual(mcb1.getAttribute("placeholder"), "Some initial text", "Should have placeholder");
assert.strictEqual(mcb2.getAttribute("placeholder"), "", "Shouldn't have placeholder when there are tokens");
});
});
});