-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
JSX render won't allow webkitdirectory and directory to be used #3468
Comments
We currently have a whitelist of supported attributes. We want to remove the whitelist and allow all attributes at some point (#140) but it's tricky because some components pass all attributes to their children. Edit: Actually, changed my mind, we'll leave this one open to track the addition of A #goodfirstbug might be to add these to the whitelist. |
webkitdirectory was added by #3644. |
Still need |
I think we're pretty unlikely to take it for the next release (very soon) and we'll hopefully get to a point before the next release after that where all attrs will work without the whitelist. So I'm not super inclined to spend any effort here at the moment. |
Fair enough, I reckon this can be closed then! |
@zpao any news regarding being able to use mozdirectory and the rest with or without the whitelist? |
BUMP!Is |
Guys it's such a required feature. Is there any workaround for it? |
We intend to drop the whitelist and pass all attributes through, possibly in React 16. |
In the meantime you can do this in |
@gaearon I'm doing that right now, but that's just a dirty hack. Plus, going through the PRs I noticed one that suggests that we might be getting warnings about direct DOM manipulations in the future, so there's that 😟 |
Thanks @gaearon for the update and possible workaround. |
Yeah I did this:
but I just don't like these lines in my code. |
Though of course we can wait till react 16 is out. |
Setting the html tag attributes in
To solve this I had to do this:
I guess doing this every time |
@sassanh isn't string refs deprecated? I'm doing it like, ...
render () {
return (
<input ref={i => this._inp = i} type='file' />
)
}
componentDidMount () {
this._inp.nwdirectory = true
} As for your conditional you could just define an empty object called |
@fa7ad string refs are legacy, but not deprecated yet.
|
@aweary sorry, missed that. Been a long time since I visited the site. Anyhow, since we know why this is a wontfix, can we close this? |
@fa7ad actually I like the legacy string refs. They're great for simple use-cases like this and don't force you to define another variable on your class. I'm sure there are use-cases for new function refs but for simple use-cases like this I prefer string refs. I hope it'll never get deprecated. |
I’m not sure what you’re referring to, but touching DOM from lifecycle hooks was (and will be) allowed as long as you’re careful to not mess up the tree controlled by React.
Yes, but you can fix this by using callback refs instead and doing the work in the ref callback. _addDirectory(node) {
if (node) {
node.directory = true;
node.webkitdirectory = true;
}
}
render() {
return this.context.pending
? <input ref={node => this._addDirectory(node)} type='file'/>
: <div>y</div>;
}
Ironically this is exactly the situation where callback refs do the job better 😄 . You don’t have to use them to define a variable on the class, you can do any work inside them (including adding attributes like I showed above).
They will. |
Yeah, a good use-case for refs. But this is not the same use-case as above, to keep a reference to a dom element simply to do a manipulation on it later I still prefer string refs over storing it on a variable in class - though I hope I don't need to do that at all, maybe when react is version 1 someday we don't feel the need to use it. |
@sassanh react is version 15 right now, so... 😕 |
Oh I thought it's version .15. I searched react in google and went to https://facebook.github.io/react/ to check it out, then went to my |
- uses chrome webkitdirectory for uploading folders - currently using componentWillMount to set webkitdirectory attribute due to how react treats this attribute, see link below - facebook/react#3468
This will be supported in React 16. https://facebook.github.io/react/blog/2017/09/08/dom-attributes-in-react-16.html |
Is it just me, or is this still not supported in React 16? I'm on ^16.6.0 of React and ReactDOM and I'm having exactly the issues described here. And I don't think the workaround works in TypeScript. |
It works for me if I add empty string <input directory="" webkitdirectory="" type="file" /> |
this does not seems to be working..
|
@softmarshmallow this might have to do with the typescript typings rather than an issue in React itself. Last I checked, the empty string thing works in normal JavaScript just fine. |
@softmarshmallow I was able to fix this issue by doing this You should check this out: https://stackoverflow.com/questions/43618878/how-to-disable-a-ts-rule-for-a-specific-line
|
I am still facing this issue. no error is thrown. It just doesn't work |
In my case, it got fixed by removing styled-components |
Use above code after your imports , then you can use both directory and webkitdirectory. its works in tsx and jsx files. |
Nice one, but I believe the type would be |
Nope, it doesn't work with React if you use a boolean. Who knows when they'll be added to the whitelist, or if React is even still using a whitelist. |
I tried to use webkitdirectory and directory in the input DOM. But I found that it is impossible to add these two label to the input DOM. Anyway to solve this problem?
The text was updated successfully, but these errors were encountered: