@aquera/nile-elements 0.0.25 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent nile-elements following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "nile-elements",
6
- "version": "0.0.25",
6
+ "version": "0.0.26",
7
7
  "main": "dist/src/index.js",
8
8
  "type": "module",
9
9
  "module": "dist/src/index.js",
@@ -613,27 +613,29 @@ export class NileSelect extends NileElement implements NileFormControl {
613
613
  // Get all options as an array
614
614
  const options = [...this.querySelectorAll<NileOption>('nile-option')];
615
615
 
616
- // Sort the options based on the order of values in this.oldValue
617
- options.sort((a, b) => {
618
- let indexA = this.oldValue.indexOf(a.value);
619
- let indexB = this.oldValue.indexOf(b.value);
620
-
621
- // Handle cases where a __value is not found in this.oldValue
622
- if (indexA === -1) {
623
- indexA = Infinity; // Place at the end if not found
624
- }
625
- if (indexB === -1) {
626
- indexB = Infinity; // Place at the end if not found
627
- }
616
+ // Sort the options based on the order of values selected
617
+ if (this.multiple && this.oldValue?.length > 0) {
618
+ options.sort((a, b) => {
619
+ let indexA = this.oldValue.indexOf(a.value);
620
+ let indexB = this.oldValue.indexOf(b.value);
621
+
622
+ // Handle cases where a __value is not found
623
+ if (indexA === -1) {
624
+ indexA = Infinity; // Place at the end if not found
625
+ }
626
+ if (indexB === -1) {
627
+ indexB = Infinity; // Place at the end if not found
628
+ }
628
629
 
629
- if (indexA < indexB) {
630
- return -1;
631
- }
632
- if (indexA > indexB) {
633
- return 1;
634
- }
635
- return 0;
636
- });
630
+ if (indexA < indexB) {
631
+ return -1;
632
+ }
633
+ if (indexA > indexB) {
634
+ return 1;
635
+ }
636
+ return 0;
637
+ });
638
+ }
637
639
 
638
640
  return options;
639
641
  }