Skip to content

Commit cd5fad2

Browse files
authored
fix(ui5-multi-combobox): make focus outline visible (#2431)
FIXES: #2286
1 parent 58b301f commit cd5fad2

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

packages/main/src/MultiComboBox.hbs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<div class="ui5-multi-combobox-root"
2-
@focusin={{rootFocusIn}}
3-
@focusout={{rootFocusOut}}
42
>
53
<span id="{{_id}}-hiddenText-nMore" class="ui5-hidden-text">{{nMoreCountText}}</span>
64

@@ -15,6 +13,7 @@
1513
@ui5-show-more-items-press="{{_showMorePopover}}"
1614
@ui5-token-delete="{{_tokenDelete}}"
1715
@focusout="{{_tokenizerFocusOut}}"
16+
@focusin="{{_tokenizerFocusIn}}"
1817
@click={{_click}}
1918
@keydown="{{_onTokenizerKeydown}}"
2019
?expanded="{{_tokenizerExpanded}}"
@@ -46,6 +45,8 @@
4645
@keydown="{{_onkeydown}}"
4746
@keyup="{{_onkeyup}}"
4847
@click={{_click}}
48+
@focusin={{inputFocusIn}}
49+
@focusout={{inputFocusOut}}
4950
role="combobox"
5051
aria-haspopup="listbox"
5152
aria-expanded="{{open}}"

packages/main/src/MultiComboBox.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ const metadata = {
222222
type: Boolean,
223223
},
224224

225-
_rootFocused: {
225+
focused: {
226+
type: Boolean,
227+
},
228+
229+
_tokenizerFocused: {
226230
type: Boolean,
227231
},
228232

@@ -514,6 +518,8 @@ class MultiComboBox extends UI5Element {
514518
}
515519

516520
_tokenizerFocusOut(event) {
521+
this._tokenizerFocused = false;
522+
517523
const tokenizer = this.shadowRoot.querySelector("[ui5-tokenizer]");
518524
const tokensCount = tokenizer.tokens.length - 1;
519525

@@ -533,6 +539,11 @@ class MultiComboBox extends UI5Element {
533539
}
534540
}
535541

542+
_tokenizerFocusIn() {
543+
this._tokenizerFocused = true;
544+
this.focused = false;
545+
}
546+
536547
_onkeyup() {
537548
this._keyDown = false;
538549
}
@@ -733,22 +744,26 @@ class MultiComboBox extends UI5Element {
733744
return this.i18nBundle.getText(TOKENIZER_ARIA_CONTAIN_SEVERAL_TOKENS, iTokenCount);
734745
}
735746

736-
rootFocusIn() {
747+
inputFocusIn() {
737748
if (!isPhone()) {
738-
this._rootFocused = true;
749+
this.focused = true;
739750
}
740751
}
741752

742-
rootFocusOut(event) {
753+
inputFocusOut(event) {
743754
if (!this.shadowRoot.contains(event.relatedTarget) && !this._deleting) {
744-
this._rootFocused = false;
755+
this.focused = false;
745756
}
746757
}
747758

748759
get editable() {
749760
return !this.readonly;
750761
}
751762

763+
get _isFocusInside() {
764+
return this.focused || this._tokenizerFocused;
765+
}
766+
752767
get selectedItemsListMode() {
753768
return this.readonly ? "None" : "MultiSelect";
754769
}
@@ -782,7 +797,7 @@ class MultiComboBox extends UI5Element {
782797
}
783798

784799
get shouldDisplayOnlyValueStateMessage() {
785-
return this._rootFocused && this.hasValueStateMessage && !this._iconPressed;
800+
return this.focused && this.hasValueStateMessage && !this._iconPressed;
786801
}
787802

788803
get valueStateTextMappings() {
@@ -816,7 +831,7 @@ class MultiComboBox extends UI5Element {
816831
}
817832

818833
get _tokenizerExpanded() {
819-
return (this._rootFocused || this.open) && !this.readonly;
834+
return (this._isFocusInside || this.open) && !this.readonly;
820835
}
821836

822837
get classes() {

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ describe("MultiComboBox general interaction", () => {
1616
assert.ok(!popover.getProperty("opened"), "Popover should close");
1717
});
1818

19+
it("Checks focus state", () => {
20+
const mcb = browser.$("#multi1");
21+
const input = mcb.shadow$("#ui5-multi-combobox-input");
22+
23+
input.click();
24+
25+
assert.ok(mcb.getProperty("focused"), "MultiComboBox should be focused.");
26+
27+
input.keys("ArrowLeft");
28+
29+
assert.notOk(mcb.getProperty("focused"), "MultiComboBox should no longer be focused.");
30+
31+
input.keys("ArrowRight");
32+
33+
assert.ok(mcb.getProperty("focused"), "MultiComboBox should be focused again.");
34+
});
35+
1936
it("MultiComboBox open property is set correctly", () => {
2037
const mcb = browser.$("#multi1");
2138
const icon = browser.$("#multi1").shadow$("[input-icon]");
@@ -188,8 +205,6 @@ describe("MultiComboBox general interaction", () => {
188205
let tokens = $("#multi1").shadow$$(".ui5-multi-combobox-token");
189206
const input = $("#multi1").shadow$("input");
190207

191-
$("#multi1").setProperty("value", "");
192-
193208
input.click();
194209
input.keys('Backspace');
195210

0 commit comments

Comments
 (0)