Skip to content
Open
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
55 changes: 45 additions & 10 deletions src/bundle/Resources/public/js/scripts/core/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,37 @@
return this.onSelect(optionToSelect, true);
}

onSelect(element, selected) {
const { choiceIcon } = element.dataset;
const value = JSON.stringify(String(element.dataset.value));
getValueFromElement(element, isJSONValue = true) {
const value = String(element.dataset.value);

if (this.canSelectOnlyOne && selected) {
this.hideOptions();
this.clearCurrentSelection(false);
if (!isJSONValue) {
return value;
}

return JSON.stringify(String(element.dataset.value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return JSON.stringify(String(element.dataset.value));
return JSON.stringify(value);

}

onSelectSetSourceInputState(element, selected) {
const value = this.getValueFromElement(element);

if (value) {
this.sourceInput.querySelector(`[value=${value}]`).selected = selected;
}
}

if (!this.canSelectOnlyOne) {
element.querySelector('.ibexa-input').checked = selected;
}
onSelectSetItemsListState(element, selected) {
const value = this.getValueFromElement(element);

if (value && !this.canSelectOnlyOne) {
element.querySelector('.ibexa-input').checked = selected;
}

this.itemsListContainer.querySelector(`[data-value=${value}]`).classList.toggle('ibexa-dropdown__item--selected', selected);
}

onSelectSetSelectionInfoState(element, selected) {
const { choiceIcon } = element.dataset;
const value = this.getValueFromElement(element);
const selectedItemsList = this.container.querySelector('.ibexa-dropdown__selection-info');

if (selected) {
Expand All @@ -218,6 +230,10 @@
}

this.fitItems();
}

onSelectSetCurrentSelectedValueState(element) {
const value = this.getValueFromElement(element);

if (this.currentSelectedValue !== value || !this.canSelectOnlyOne) {
this.fireValueChangedEvent();
Expand All @@ -226,6 +242,18 @@
}
}

onSelect(element, selected) {
if (this.canSelectOnlyOne && selected) {
this.hideOptions();
this.clearCurrentSelection(false);
}

this.onSelectSetSourceInputState(element, selected);
this.onSelectSetItemsListState(element, selected);
this.onSelectSetSelectionInfoState(element, selected);
this.onSelectSetCurrentSelectedValueState(element, selected);
}

onInteractionOutside(event) {
if (this.itemsPopover.tip.contains(event.target)) {
return;
Expand Down Expand Up @@ -293,6 +321,13 @@
this.fireValueChangedEvent();
}

deselectOptionByValue(value) {
const stringifiedValue = JSON.stringify(String(value));
const optionToDeselect = this.itemsListContainer.querySelector(`.ibexa-dropdown__item[data-value=${stringifiedValue}]`);

return this.deselectOption(optionToDeselect);
}

fitItems() {
if (this.canSelectOnlyOne) {
return;
Expand Down Expand Up @@ -526,7 +561,7 @@
);
this.itemsPopover._element.removeAttribute('title');

if (this.isDynamic) {
if (this.isDynamic && this.canSelectOnlyOne) {
this.selectFirstOption();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
attributeFilter: ['disabled'],
attributeOldValue: true,
});

ibexa.helpers.objectInstances.setInstance(this.container, this);
}

toggleEmptyListState() {
Expand Down
7 changes: 6 additions & 1 deletion src/bundle/Resources/public/scss/_tag-view-select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@
display: flex;
}

&__btn-select-path {
&__actions {
margin-top: calculateRem(24px);
}

&__separator {
display: inline-block;
padding: 0 calculateRem(16px);
}

&:disabled,
&[disabled] {
@include colorful-tags($ibexa-color-dark-400, $ibexa-color-light-300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,45 +68,59 @@
})|e('html_attr') }}"
data-placeholder-template="{{ placeholder_list_item|e('html_attr') }}"
>
{% if no_items %}
{% if not is_dynamic %}
{{ placeholder_list_item }}
{% endif %}
{% else %}
{% if value is empty %}
{% if not multiple %}
{% if placeholder is defined and placeholder is not none %}
{% set default_label = 'dropdown.placeholder.all'|trans()|desc('All') %}

{% include selected_item_template_path with {
value: '',
label: _self.get_translated_label(placeholder, translation_domain)|trim|default(default_label),
} %}
{% else %}
{% set first_choice = choices_flat|first %}

{% include selected_item_template_path with {
value: first_choice.value,
label: _self.get_translated_label(first_choice.label, translation_domain),
icon: first_choice.icon is defined ? first_choice.icon,
} %}
{% endif %}
{% block selection_info_content %}
{% if no_items %}
{% if not is_dynamic %}
{{ placeholder_list_item }}
{% endif %}
{% else %}
{% for choice in choices_flat %}
{% if custom_form ? choice.value == value : choice is selectedchoice(value) %}
{% set label = selected_item_label is defined
? selected_item_label
: _self.get_translated_label(choice.label, translation_domain)
%}
{% if value is empty %}
{% if not multiple %}
{% if placeholder is defined and placeholder is not none %}
{% set default_label = 'dropdown.placeholder.all'|trans()|desc('All') %}

{% include selected_item_template_path with {
label,
value: choice.value,
icon: choice.icon is defined ? choice.icon,
} %}
{% include selected_item_template_path with {
value: '',
label: _self.get_translated_label(placeholder, translation_domain)|trim|default(default_label),
} %}
{% else %}
{% set first_choice = choices_flat|first %}

{% include selected_item_template_path with {
value: first_choice.value,
label: _self.get_translated_label(first_choice.label, translation_domain),
icon: first_choice.icon is defined ? first_choice.icon,
} %}
{% endif %}
{% endif %}
{% endfor %}
{% else %}
{% for choice in choices_flat %}
{% if custom_form ? choice.value == value : choice is selectedchoice(value) %}
{% set label = selected_item_label is defined
? selected_item_label
: _self.get_translated_label(choice.label, translation_domain)
%}

{% include selected_item_template_path with {
label,
value: choice.value,
icon: choice.icon is defined ? choice.icon,
} %}
{% endif %}
{% endfor %}
{% endif %}
{% if multiple %}
<li
class="ibexa-dropdown__selected-item ibexa-dropdown__selected-item--predefined ibexa-dropdown__selected-placeholder"
{% if value is empty %}hidden{% endif %}
>
{% if placeholder is defined and placeholder is not none %}
{{ _self.get_translated_label(placeholder, translation_domain )}}
{% else %}
{{ 'dropdown.placeholder'|trans|desc("Choose an option") }}
{% endif %}
</li>
{% endif %}
{% endif %}
{% if multiple %}
<li
Expand All @@ -122,7 +136,7 @@
</span>
</li>
{% endif %}
{% endif %}
{% endblock selection_info_content %}

<li class="ibexa-dropdown__selected-item ibexa-dropdown__selected-item--predefined ibexa-dropdown__selected-overflow-number" hidden></li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,24 @@
attr: { hidden: true }
}) }}
{% endif %}
<button
type="button"
{{ html.attributes(attr|default({})) }}
>
<span
class="ibexa-btn__label ibexa-tag-view-select__btn-label ibexa-tag-view-select__btn-label--select"
{% if is_single_select and has_value %}hidden{% endif %}
<div class="ibexa-tag-view-select__actions">
<button
type="button"
{{ html.attributes(attr|default({})) }}
>
{{ 'tag_view_select.select'|trans({ '%type%': type })|desc('Select %type%') }}
</span>
<span
class="ibexa-btn__label ibexa-tag-view-select__btn-label ibexa-tag-view-select__btn-label--change"
{% if (is_single_select and not has_value) or not is_single_select %}hidden{% endif %}
>
{{ 'tag_view_select.change'|trans({ '%type%': type })|desc('Change %type%') }}
</span>
</button>
<span
class="ibexa-btn__label ibexa-tag-view-select__btn-label ibexa-tag-view-select__btn-label--select"
{% if is_single_select and has_value %}hidden{% endif %}
>
{{ 'tag_view_select.select'|trans({ '%type%': type })|desc('Select %type%') }}
</span>
<span
class="ibexa-btn__label ibexa-tag-view-select__btn-label ibexa-tag-view-select__btn-label--change"
{% if (is_single_select and not has_value) or not is_single_select %}hidden{% endif %}
>
{{ 'tag_view_select.change'|trans({ '%type%': type })|desc('Change %type%') }}
</span>
</button>
{{ extra_actions|default('') }}
</div>
</div>
Loading