Skip to content

Commit 6f00340

Browse files
committed
IBX-7173: As the user I want to see empty state message in dropdown while filtering
1 parent 434a82b commit 6f00340

File tree

6 files changed

+54
-22
lines changed

6 files changed

+54
-22
lines changed

src/bundle/Resources/config/bazinga_js_translation.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ active_domains:
1111
- 'ibexa_trash_ui'
1212
- 'ibexa_user_invitation'
1313
- 'ibexa_content_type'
14+
- 'ibexa_dropdown'
1415
- 'messages'

src/bundle/Resources/public/js/scripts/core/dropdown.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
this.itemsContainer = this.container.querySelector('.ibexa-dropdown__items');
3737
this.itemsListContainer = this.itemsContainer.querySelector('.ibexa-dropdown__items-list');
3838
this.itemsFilterInput = this.itemsContainer.querySelector('.ibexa-dropdown__items-filter');
39+
this.itemsListFilterEmptyContainer = this.itemsContainer.querySelector('.ibexa-dropdown__items-list-filter-empty');
3940
this.selectionTogglerBtn = this.itemsContainer.querySelector('.ibexa-dropdown__selection-toggler-btn');
4041

4142
this.isDynamic = this.container.classList.contains('ibexa-dropdown--dynamic');
@@ -308,24 +309,35 @@
308309
}
309310

310311
filterItems(event) {
311-
const forceShowItems = event.currentTarget.value.length < MINIMUM_LETTERS_TO_FILTER;
312+
const searchedTerm = event.currentTarget.value;
313+
const forceShowItems = searchedTerm.length < MINIMUM_LETTERS_TO_FILTER;
312314
const allItems = [...this.itemsListContainer.querySelectorAll('[data-filter-value]')];
313315
const groups = [...this.itemsListContainer.querySelectorAll('.ibexa-dropdown__item-group')];
314316
const separator = this.itemsListContainer.querySelector('.ibexa-dropdown__separator');
317+
const emptyMessage = Translator.trans(
318+
/*@Desc("No results found for &quot;%phrase%&quot;")*/ 'dropdown.no_results',
319+
{ phrase: searchedTerm },
320+
'ibexa_dropdown',
321+
);
315322
let hideSeparator = true;
323+
let anyItemVisible = false;
316324

317325
if (separator) {
318326
separator.setAttribute('hidden', 'hidden');
319327
}
320328

321329
allItems.forEach((item) => {
322-
const isItemVisible = forceShowItems || this.compareItem(item.dataset.filterValue, event.currentTarget.value);
330+
const isItemVisible = forceShowItems || this.compareItem(item.dataset.filterValue, searchedTerm);
323331
const isPreferredChoice = item.classList.contains('ibexa-dropdown__item--preferred-choice');
324332

325333
if (isPreferredChoice && isItemVisible) {
326334
hideSeparator = false;
327335
}
328336

337+
if (isItemVisible) {
338+
anyItemVisible = true;
339+
}
340+
329341
item.classList.toggle('ibexa-dropdown__item--hidden', !isItemVisible);
330342
});
331343

@@ -338,6 +350,10 @@
338350
if (separator && !hideSeparator) {
339351
separator.removeAttribute('hidden');
340352
}
353+
354+
this.itemsListContainer.toggleAttribute('hidden', !anyItemVisible);
355+
this.itemsListFilterEmptyContainer.toggleAttribute('hidden', anyItemVisible);
356+
this.itemsListFilterEmptyContainer.querySelector('.ibexa-dropdown__items-list-filter-empty-message').innerHTML = emptyMessage;
341357
}
342358

343359
itemsPopoverContent() {
@@ -434,9 +450,9 @@
434450
? Translator.trans(
435451
/*@Desc("Clear (%selected_items_count%)")*/ 'dropdown.clear',
436452
{ selected_items_count: selectedItems.length },
437-
'messages',
453+
'ibexa_dropdown',
438454
)
439-
: Translator.trans(/*@Desc("Select All")*/ 'dropdown.select_all', {}, 'messages');
455+
: Translator.trans(/*@Desc("Select All")*/ 'dropdown.select_all', {}, 'ibexa_dropdown');
440456

441457
this.selectionTogglerBtn.innerHTML = label;
442458
}

src/bundle/Resources/public/scss/_dropdown.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@
211211
overflow-y: auto;
212212
}
213213

214+
&__items-list-filter-empty {
215+
padding: calculateRem(16px);
216+
text-align: center;
217+
}
218+
219+
&__items-list-filter-empty-message {
220+
color: $ibexa-color-dark-400;
221+
font-size: $ibexa-text-font-size;
222+
font-weight: 600;
223+
line-height: calculateRem(24px);
224+
padding: calculateRem(24px) 0;
225+
}
226+
214227
&__item-check {
215228
position: absolute;
216229
right: calculateRem(4px);

src/bundle/Resources/translations/ibexa_dropdown.en.xliff

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
<target state="new">Clear (%selected_items_count%)</target>
1212
<note>key: dropdown.clear</note>
1313
</trans-unit>
14+
<trans-unit id="ada9f9b1f9f1b312d3b2de5dbdbcf89065f72608" resname="dropdown.no_results">
15+
<source><![CDATA[No results found for &quot;%phrase%&quot;]]></source>
16+
<target state="new"><![CDATA[No results found for &quot;%phrase%&quot;]]></target>
17+
<note>key: dropdown.no_results</note>
18+
</trans-unit>
1419
<trans-unit id="a3390555f717ffd9b3560f17198e5a437899967f" resname="dropdown.placeholder">
1520
<source>Choose an option</source>
1621
<target state="new">Choose an option</target>

src/bundle/Resources/translations/messages.en.xliff

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,11 @@
261261
<target state="new">No results found</target>
262262
<note>key: dashboard.charts.no_results</note>
263263
</trans-unit>
264-
<trans-unit id="8fedbb70c8494c057fb45930e46671a659bae616" resname="dropdown.clear">
265-
<source>Clear (%selected_items_count%)</source>
266-
<target state="new">Clear (%selected_items_count%)</target>
267-
<note>key: dropdown.clear</note>
268-
</trans-unit>
269264
<trans-unit id="272e650f8667b4f4fcb7032b85b98ef4a9974f0f" resname="dropdown.search">
270265
<source>Search...</source>
271266
<target state="new">Search...</target>
272267
<note>key: dropdown.search</note>
273268
</trans-unit>
274-
<trans-unit id="3f446c9bfc8591ebdb9a2bc8fa98410bdcc4ced2" resname="dropdown.select_all">
275-
<source>Select All</source>
276-
<target state="new">Select All</target>
277-
<note>key: dropdown.select_all</note>
278-
</trans-unit>
279269
<trans-unit id="7cb40cbc703336ab1285e81ebf100b82b05a0e27" resname="error.page.403.actions">
280270
<source><![CDATA[Contact your administrator to request access.<br/>Go back to the <a href="%dashboard%">dashboard</a> or <a href="%search%">search</a> for another item.]]></source>
281271
<target state="new"><![CDATA[Contact your administrator to request access.<br/>Go back to the <a href="%dashboard%">dashboard</a> or <a href="%search%">search</a> for another item.]]></target>

src/bundle/Resources/views/themes/admin/ui/component/dropdown/dropdown.html.twig

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@
123123
<li class="ibexa-dropdown__selected-item ibexa-dropdown__selected-item--predefined ibexa-dropdown__selected-overflow-number" hidden></li>
124124
</ul>
125125
<div class="ibexa-dropdown__items {{ items_class|default('') }} {{ choices_flat|length < min_search_items ? 'ibexa-dropdown__items--search-hidden' }}">
126+
{% block items_list_header %}
127+
{% if items_list_header is defined %}
128+
<div class="ibexa-dropdown__items-list-header">
129+
{{ items_list_header }}
130+
</div>
131+
{% endif %}
132+
{% endblock items_list_header %}
133+
126134
{%- embed '@ibexadesign/ui/component/input_text.html.twig' with { has_search: true } only -%}
127135
{% block content %}
128136
<input
@@ -144,14 +152,6 @@
144152
</button>
145153
{% endif %}
146154

147-
{% block items_list_header %}
148-
{% if items_list_header is defined %}
149-
<div class="ibexa-dropdown__items-list-header">
150-
{{ items_list_header }}
151-
</div>
152-
{% endif %}
153-
{% endblock items_list_header %}
154-
155155
<ul
156156
class="ibexa-dropdown__items-list"
157157
data-template="{{ include(list_item_template_path, {
@@ -183,6 +183,13 @@
183183
{% include list_item_template_path with { choice, custom_form, icon: item_icon, icon_class: item_icon_class } %}
184184
{% endfor %}
185185
</ul>
186+
187+
<div class="ibexa-dropdown__items-list-filter-empty" hidden>
188+
<svg>
189+
<use xlink:href="{{ ibexa_icon_path('filter-empty') }}"></use>
190+
</svg>
191+
<div class="ibexa-dropdown__items-list-filter-empty-message"></div>
192+
</div>
186193
</div>
187194
</div>
188195
</div>

0 commit comments

Comments
 (0)