primefaces / primeng

The Most Complete Angular UI Component Library
https://primeng.org
Other
10.18k stars 4.55k forks source link

p-cascadeSelect: `options` input type mismatch with official documentation. #13466

Open Gykonik opened 1 year ago

Gykonik commented 1 year ago

Describe the bug

The CascadeComponent defines the options input as:

@Input() options: string[] | string | undefined | null; Source

However, the official documentation provides an example where options is expected to be an array of objects:

<p-cascadeSelect [(ngModel)]="selectedCity" [options]="countries" optionLabel="cname" optionGroupLabel="name" [optionGroupChildren]="['states', 'cities']" [style]="{ minWidth: '14rem' }" placeholder="Select a City"></p-cascadeSelect>

With the corresponding data:

this.countries = [
  {
    name: 'Australia',
    code: 'AU',
    states: [
      {
        name: 'New South Wales',
        cities: [
          { cname: 'Sydney', code: 'A-SY' },
          { cname: 'Newcastle', code: 'A-NE' },
          { cname: 'Wollongong', code: 'A-WO' }
        ]
      },
      {
        name: 'Queensland',
        cities: [
          { cname: 'Brisbane', code: 'A-BR' },
          { cname: 'Townsville', code: 'A-TO' }
        ]
      }
    ]
  },
  ...
];

Environment

Angular 16 PrimeNG 16

Reproducer

No response

Angular version

16.1.2

PrimeNG version

16.0.2

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

The type definition for the options input should match the official documentation (or the other way around) and support arrays of objects. Or am I missing anything obvious here?

Gykonik commented 1 year ago

Furthermore, I think that it needs undefined-checks for isOptionGroup:

isOptionGroup(option: string | object, level: number) {
  return Object.prototype.hasOwnProperty.call(option, (this.optionGroupChildren as string)[level]);
}

source

  1. I think it should be as string[] or even as any as it was done in OptionGroupSub reference
  2. This fails when not passing in any option for optionGroupChildren or passing a string.
jesuscano80 commented 8 months ago

Any news about this?

pmestrum commented 7 months ago

I am also blocked because of this bug, since I upgraded vrom v15 to latest version.

randy9527 commented 5 months ago

Source of Cascade Select is always hierarchical objects, string[] | string | undefined | null really doesn't make sense.

toute-la-journee commented 4 months ago

any updates?

ThreatLockerNathanHolden commented 4 months ago

Reporting the same issue after upgrading project from PrimeNG v15.4.1 to v16.9.1.

msg-jstren commented 1 week ago

Type issue for the options input still remains on PrimeNG version 17.18.8 Should have an Interface with hierarchical objects!