Topic: Dropdown visibility prop produces a DOM warning

devCorner free asked 1 week ago


Our wrapper passes a visibility flag into MDBDropdown. React reports an unknown attribute, and the menu ignores the state value.

Where should the controlled property be applied?


Mateusz Lazaru staff answered 1 week ago


The warning indicates that your visibility flag reaches a native DOM element instead of being consumed by a supported component interface. Check your wrapper's spread props first and remove that custom flag from the props forwarded to its div or other native element.

Please send the wrapper, MDBDropdown/MDBDropdownMenu JSX, and exact warning. Do not rename the flag to a lowercase DOM attribute to silence the warning; that will not make the menu controlled. We can then identify where the value is forwarded and how menu visibility should be updated.

https://mdbootstrap.com/docs/react/components/dropdowns/


devCorner free commented 1 week ago

I removed the flag from MDBDropdown, but the warning remained in our shared button. The menu opens normally through MDBDropdownToggle. We also pass menuOpen to this wrapper for a visual state, and it forwards everything to the native button. Should that flag be handled here?

function ActionButton(props) {
  return <button type="button" {...props} />;
}
<ActionButton menuOpen={menuOpen} onClick={handleAction}>
  Actions
</ActionButton>

Mateusz Lazaru staff commented 1 week ago

Yes. Destructure menuOpen before spreading the remaining button props, and use it only for the styling your wrapper owns. It will then stop reaching the native element as an unknown attribute.

Keep the working MDBDropdownToggle responsible for opening the menu. The is-open class below is just a visual state for this shared button; it does not control the dropdown's visibility.

function ActionButton({ menuOpen, className = '', children, ...buttonProps }) {
  const classes = [className, menuOpen ? 'is-open' : ''].filter(Boolean).join(' ');
  return (
    <button {...buttonProps} type="button" className={classes}>
      {children}
    </button>
  );
}


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: MDB5 9.0.0
  • Device: Desktop
  • Browser: Chrome
  • OS: macOS
  • Provided sample code: No
  • Provided link: No