diff --git a/panel/tests/widgets/test_select.py b/panel/tests/widgets/test_select.py index f19c4298bd..207fe1dfdc 100644 --- a/panel/tests/widgets/test_select.py +++ b/panel/tests/widgets/test_select.py @@ -302,3 +302,13 @@ def test_cross_select_move_unselected_to_selected(): assert cross_select.value == ['A', 1, 'B', 3] assert cross_select._lists[True].options == ['A', 'B', '1', '3'] + + +def test_cross_select_move_unselected_to_selected_not_definition_order(): + cross_select = CrossSelector(options=['B', 'A', 'C', 1, 2, 3], value=['A', 1], size=5, definition_order=False) + + cross_select._lists[False].value = ['B', '3'] + cross_select._buttons[True].clicks = 1 + + assert cross_select.value == ['A', 1, 'B', 3] + assert cross_select._lists[True].options == ['A', '1', 'B', '3'] diff --git a/panel/widgets/select.py b/panel/widgets/select.py index bf53be7a56..ecbba00d45 100644 --- a/panel/widgets/select.py +++ b/panel/widgets/select.py @@ -300,6 +300,10 @@ class CrossSelector(CompositeWidget, MultiSelect): The number of options shown at once (note this is the only way to control the height of this widget)""") + definition_order = param.Integer(default=True, doc=""" Whether to + preserve definition order after filtering. Disable to allow the + order of selection to define the order of the selected list.""") + def __init__(self, *args, **kwargs): super(CrossSelector, self).__init__(**kwargs) # Compute selected and unselected values @@ -418,7 +422,10 @@ def _apply_query(self, selected): query = self._query[selected] other = self._lists[not selected].labels labels = self.labels - options = [k for k in labels if k not in other] + if self.definition_order: + options = [k for k in labels if k not in other] + else: + options = self._lists[selected].values if not query: self._lists[selected].options = options self._lists[selected].value = []