-
Notifications
You must be signed in to change notification settings - Fork 81
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
React doesn't play nice with inert property #58
Comments
Closing this as it's a React specific issue and I just wanted to document the workaround. You can see the discussion on React allowing custom attributes/properties here: facebook/react#140 |
Just to extend this a little, if you want conditional inertness in React you need something more like: <div
ref={node => node && (shouldBeInert ?
node.setAttribute('inert', '') : node.removeAttribute('inert')
)}
/> |
Thank you Tim! |
I am receiving |
@maracuja-juice you're getting this following @robdodson's example ? hey @robdodson - the link above showing a functional snip at https://www.webpackbin.com/bins/-KmmTaOzo6tSQqTeIv2H appears to be gone |
@bkardell I'm using pimterry's example but I guess I will have the exact same behaviour if I would use the original suggestion as they're not that different. |
Can you share any running code? Can you add a debugger and see what node is there? |
Hm this sounds like an issue with how @maracuja-juice is using refs in React. I'm not super familiar with React but maybe in newer versions the ref syntax has changed? |
i'd just like to add that the following works for both adding and removing <div inert={inertCondition ? '' : null} /> |
If you're by any chance using React with TypeScript and Linaria, do this:
Then, as @defnotrobbie suggested, you can use inert conditionally, and TypeScript will still be happy because we defined an additional prop:
|
If anyone needs a workaround until this is implemented I have solved it like this:
inert undefined will not pass inert to the underlying DOM element and inert="" will pass to the DOM node and works like inert={true} then:
|
Declaring on declare module 'react' {
interface HTMLAttributes<T> extends DOMAttributes<T> {
/**
* Boolean attribute indicating that the browser will ignore the element.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inert MDN Web Docs}
*/
inert?: '';
}
} |
Example: https://www.webpackbin.com/bins/-KmmTaOzo6tSQqTeIv2H
React will ignore attempts to set the
inert
prop because it doesn't allow setting non-standard or experimental props on a node. https://facebook.github.io/react/warnings/unknown-prop.htmlThe workaround is to use the node's ref to set the inert attribute instead.
The text was updated successfully, but these errors were encountered: