primeng icon indicating copy to clipboard operation
primeng copied to clipboard

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

Open Gykonik opened this issue 1 year ago • 7 comments

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 avatar Aug 08 '23 19:08 Gykonik

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.

Gykonik avatar Aug 09 '23 08:08 Gykonik

Any news about this?

jesuscano80 avatar Jan 16 '24 16:01 jesuscano80

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

pmestrum avatar Feb 04 '24 10:02 pmestrum

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

randy9527 avatar Apr 03 '24 05:04 randy9527

any updates?

toute-la-journee avatar Apr 18 '24 13:04 toute-la-journee

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

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

msg-jstren avatar Sep 04 '24 13:09 msg-jstren