Skip to content

Dropdown with inline JS issue in 3.9.4 #1167

@Tchekda

Description

@Tchekda

Description

After upgrading to v3.9.4, I faced a major problem with my dropdown.

Steps to Reproduce

  1. Update to v3.9.4
  2. Create a Dropdown looking like this one :
    (You can obviously use any bool condition instead of hasRole)
<Dropdown
  id="security-dropdown"
  trigger={
    <a href="#!">
      Sécurité <Icon right>arrow_drop_down</Icon>
    </a>
  }>
  {hasRole('ROLE_GUARDIAN') ? (
    <>
      <Link to={`/${userType}/email`}>Adresse Mail</Link>
      <Link to={`/${userType}/other`}>Autre</Link>
    </>
  ) : (
    <Link to={`/${userType}/password`}>Mot de Passe</Link>
  )}
</Dropdown>
  1. Admire this beautiful error : TypeError: (intermediate value).filter is not a function located at renderItems xxxxx/node_modules/react-materialize/lib/Dropdown.js:54

image

Expected behavior: Display correctly the dropdown as it was working in v3.9.3

Actual behavior: The temporary fix that I found is to make to separate conditions.

<Dropdown
  id="security-dropdown"
  trigger={
    <a href="#!">
      Sécurité <Icon right>arrow_drop_down</Icon>
    </a>
  }>
  {hasRole('ROLE_GUARDIAN') && (
    <Link to={`/${userType}/email`}>Adresse Mail</Link>
  )}
  {hasRole('ROLE_GUARDIAN') && (
    <Link to={`/${userType}/other`}>Autre</Link>
  )}
  {!hasRole('ROLE_GUARDIAN') && (
    <Link to={`/${userType}/password`}>Mot de Passe</Link>
  )}
</Dropdown>

Explanations : The PR #1164 made by @MauAbata changed the way Dropdowns are rendered, that had impact on my code, and I suppose and many others.

Versions

react-materialize: 3.9.4
materialize-css: 1.0.0
react: 17.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions