Topic: Dropdown visibility prop produces a DOM warning
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 2 weeks 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 commented 2 weeks 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 2 weeks 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>
);
}
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: 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