gd-bs 6.6.9 → 6.6.10

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gd-bs",
3
- "version": "6.6.9",
3
+ "version": "6.6.10",
4
4
  "description": "Bootstrap JavaScript, TypeScript and Web Components library.",
5
5
  "main": "build/index.js",
6
6
  "typings": "src/index.d.ts",
@@ -371,6 +371,67 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
371
371
  }
372
372
  }
373
373
 
374
+ // Generates the checkbox items
375
+ private generateCheckboxItems(): ICheckboxGroupItem[] {
376
+ let cbItems: ICheckboxGroupItem[] = [];
377
+
378
+ // Parse the items
379
+ let items = this.props.items || [];
380
+ for (let i = 0; i < items.length; i++) {
381
+ let item = items[i];
382
+
383
+ // Create the checkbox item
384
+ cbItems.push({
385
+ data: item,
386
+ isDisabled: item.isDisabled,
387
+ isSelected: item.isSelected,
388
+ label: item.text,
389
+ onChange: item.onClick,
390
+ type: CheckboxGroupTypes.Checkbox
391
+ });
392
+ }
393
+
394
+ // Return the items
395
+ return cbItems;
396
+ }
397
+
398
+ // Generates the checkbox value
399
+ private generateCheckboxValue(currentValues: string | string[]): string[] {
400
+ let values: string[] = [];
401
+
402
+ // Ensure a value exists
403
+ if (currentValues == null) { return values; }
404
+
405
+ // Ensure it's an array
406
+ if (typeof (currentValues) === "string") {
407
+ // Make it an array
408
+ currentValues = [currentValues];
409
+ }
410
+
411
+ // Parse the current values
412
+ for (let i = 0; i < currentValues.length; i++) {
413
+ let value = currentValues[i];
414
+
415
+ // Find the item
416
+ let item = this.props.items?.find((item) => {
417
+ // Match by the text property if the value doesn't exist
418
+ if (typeof (item.value) === undefined) { return item.text == value; }
419
+
420
+ // See if the value property matches
421
+ return item.value == value;
422
+ });
423
+
424
+ // See if an item was found
425
+ if (item) {
426
+ // Add the text property
427
+ values.push(item.text);
428
+ }
429
+ }
430
+
431
+ // Return the values
432
+ return values;
433
+ }
434
+
374
435
  // Handles the click event outside of the menu to close it
375
436
  private handleClick = (ev: Event) => {
376
437
  // See if we clicked within the menu
@@ -395,31 +456,13 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
395
456
  if (menu) {
396
457
  // See if we are creating checkboxes
397
458
  if (this.props.isCheckbox) {
398
- let cbItems: ICheckboxGroupItem[] = [];
399
-
400
- // Parse the items
401
- let items = this.props.items || [];
402
- for (let i = 0; i < items.length; i++) {
403
- let item = items[i];
404
-
405
- // Create the checkbox item
406
- cbItems.push({
407
- data: item,
408
- isDisabled: item.isDisabled,
409
- isSelected: item.isSelected,
410
- label: item.text,
411
- onChange: item.onClick,
412
- type: CheckboxGroupTypes.Checkbox
413
- });
414
- }
415
-
416
459
  // Render the checkbox
417
460
  this._cb = CheckboxGroup({
418
461
  className: "m-2",
419
462
  el: menu,
420
- items: cbItems,
463
+ items: this.generateCheckboxItems(),
421
464
  multi: this.props.multi,
422
- value: this.props.value,
465
+ value: this.generateCheckboxValue(this.props.value),
423
466
  onChange: this.props.onChange ? (values, ev) => {
424
467
  // Pass the current values
425
468
  this.props.onChange(this.getValue(), ev);
@@ -497,8 +540,6 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
497
540
  // Add the value
498
541
  values.push(items[i].data);
499
542
  }
500
-
501
- // Return the value
502
543
  } else {
503
544
  // Parse the items
504
545
  for (let i = 0; i < this._items.length; i++) {
@@ -536,7 +577,7 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
536
577
  // See if we are rendering checkboxes
537
578
  if (this._cb) {
538
579
  // Set the items
539
- this._cb.setItems(newItems);
580
+ this._cb.setItems(this.generateCheckboxItems());
540
581
  return;
541
582
  }
542
583
 
@@ -614,6 +655,13 @@ class _Dropdown extends Base<IDropdownProps> implements IDropdown {
614
655
  // Ensure it's an array
615
656
  let values = value == null ? [] : (typeof (value.length) === "number" && typeof (value) !== "string" ? value : [value]);
616
657
 
658
+ // See if this is a checkbox
659
+ if (this._cb) {
660
+ // Set the value
661
+ this._cb.setValue(this.generateCheckboxValue(value));
662
+ return;
663
+ }
664
+
617
665
  // Parse the items
618
666
  for (let i = 0; i < this._items.length; i++) {
619
667
  let item = this._items[i];