Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown: Object not valid when you use an Empty String "" #6858

Closed
raphael-pizzo opened this issue Jul 9, 2024 · 1 comment · Fixed by #6871, #6872, leoo1992/GeradorQRCode#80 or leoo1992/GeradorQRCode#85 · May be fixed by mtech-31-quemistry/quemistry_client_web#20
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@raphael-pizzo
Copy link

Describe the bug

In my system i have an object with 2 dropdown, we can see the page in the image below:
Captura de Tela 2024-07-09 às 12 13 46

Each dropdown is an object. The first named categoriaProduto and second named fornecedor. Below the objects interface:
CategoriaProduto
export interface ICategoriaProduto {
id: number
descricao: string
status: boolean
}

export const initCategoriaProduto = (): ICategoriaProduto => ({
id: 0,
descricao: '',
status: false
})

Fornecedor:
export interface IFornecedor {
id: number
descricao: string
status: boolean
}

export const initFornecedor = (): IFornecedor => ({
id: 0,
descricao: '',
status: true
})

The 2 objects have a method to return a valid instance of the object. This instance have a simple values id (like a code in english) equals 0 (zero), descricao (description in english) equals '' and status equals true or false.

I have a principal object named ProdutoAtendimento. ProdutoAtendimento have some properties and 2 of this properties are categoriaProduto and fornecedor. Below we can see the object ProdutoAtendimento:
Captura de Tela 2024-07-09 às 12 29 49

In component, i just have a dropdown using ProdutoAtendimento object and the properties categoriaProduto and fornecedor:
Captura de Tela 2024-07-09 às 12 14 44

So, in the new version of primereact, 10.7.0, when i create an instance of categoriaProduto or fornecedor with the description equals a empty string like '' i got the error below:
Captura de Tela 2024-07-09 às 12 15 46

When i chance the properties description to any string value like 'test', the component works fine.

Thats the problem, '' is a valid string to init my component and its works fine in 10.6.6 versions and all versions.

So, to fix my application i need to go to categoriaProduto and fornecedor objects and change de instance method to use a fake value in descricao properties to my app works.

export interface ICategoriaProduto {
id: number
descricao: string
status: boolean
}

export const initCategoriaProduto = (): ICategoriaProduto => ({
id: 0,
descricao: 'test', //i put this fake value here and "fix" the problem
status: false
})

export interface IFornecedor {
id: number
descricao: string
status: boolean
}

export const initFornecedor = (): IFornecedor => ({
id: 0,
descricao: 'test', //i put this fake value here and "fix" the problem
status: true
})

Even though my paleative solution works, it still seems like a bug in the Dropdown component.
and it always worked in previous versions

Reproducer

No response

PrimeReact version

10.7.0

React version

18.x

Language

TypeScript

Build / Runtime

Next.js

Browser(s)

No response

Steps to reproduce the behavior

When you use a default value to an object with de description propertie with the default value equals an empty string like "", the dropdown component don't work. and it always worked in previous versions.

i put a fake value to "fix" my problem:
{
id: 0,
descricao: 'test', // fake value here to fix my problem
status: true
}

Expected behavior

The dropdown component needs to work, with a default value like the object below:
{
id: 0,
descricao: '',
status: true
}

@raphael-pizzo raphael-pizzo added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 9, 2024
@VytautasLozickas
Copy link
Contributor

VytautasLozickas commented Jul 11, 2024

I have the same problem. Long story short - if the label on any of the options object is an empty string - Dropdown crashes with the error when clicking on it (trying to open it):

Error: Objects are not valid as a React child (found: object with keys {value, label}). If you meant to render a collection of children, use an array instead.

Here's a quick reproducer: https://stackblitz.com/edit/vitejs-vite-diqepy?file=src%2FApp.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment