Last active
August 29, 2015 14:19
-
-
Save ericdfields/f6bdd8118229a55499af to your computer and use it in GitHub Desktop.
Disable backspace navigation when textarea has content react mixin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react') | |
var BackspaceNavHandler = require('backspace_nav_handler_mixins') | |
module.exports = React.createClass({ | |
mixins: [ BackspaceNavHandler ], | |
render: function() { | |
return ( | |
<textarea onBlur={this.disableBackspaceNav} onFocus={this.enableBackspaceNav} /> | |
) | |
} | |
}) |
Ran into a situation where the component was visible but user brought focus to an entirely unrelated field on the page and of course backspace wouldn't work. This should fix that but will probably fail in contenteditables. Needs a good "is DOM element and input" test.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may also want to make sure your input has value here, and only bother blocking the nav event if the input has content.
This is a really crude instance. Obviously if you have multiple inputs with user-generated values, you probably want something more robust.