Skip to content
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

added a selectAll boolean flag to alter focus and select behavior #57

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Components come unstyled, so take a look at [demo.jsx](https://github.com/kaivi/
* **classInvalid**: CSS class name to apply when _validate_ returned false
* **className**: CSS base class
* **editProps**: Additional props for the editing component. This allows you to, for example, specify a maxLength attribute to control the maximum number of characters in the textarea, or add `style`.
* **selectAll**: Default true. When editing, select all the input's contents if true, otherwise simply `focus()`

#### Hooks
* **beforeStart**: Fires before editing starts
Expand Down Expand Up @@ -123,4 +124,4 @@ The build process does not work with Node v6 at the moment: use [Node Version Ma
4. Open `index.html` and check if it works
5. Open JS console in browser, set `localStorage.debug = '*'` to see debug messages, add more if necessary
6. ???
7. Submit a pull request
7. Submit a pull request
16 changes: 9 additions & 7 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -20099,7 +20099,9 @@
if (_this.state.editing && !prevState.editing) {
debug('entering edit mode');
inputElem.focus();
_this.selectInputText(inputElem);
if (typeof _this.props.selectAll === 'undefined' || _this.props.selectAll) {
_this.selectInputText(inputElem);
}
} else if (_this.state.editing && prevProps.text != _this.props.text) {
debug('not editing && text not equal previous props -- finishing editing');
_this.finishEditing();
Expand Down Expand Up @@ -20236,9 +20238,9 @@
spans_and_brs.push(_react2.default.createElement('br', { key: i + 1 }));
i += 2;
});
spans_and_brs.pop // remove last br tag
spans_and_brs.pop(); // remove last br tag

();return _react2.default.createElement(
return _react2.default.createElement(
'span',
_extends({
tabIndex: '0',
Expand Down Expand Up @@ -20304,20 +20306,20 @@
};

_this.selectInputText = function (element) {
debug('selectInputText(' + element + ')'
debug('selectInputText(' + element + ')');
// element.setSelectionRange won't work for an input of type "number"
);setTimeout(function () {
setTimeout(function () {
element.select();
}, 10);
};

_this.elementBlur = function (element) {
debug('elementBlur(' + element + ')'
debug('elementBlur(' + element + ')');
/*
Firefox workaround
Found at https://tirdadc.github.io/blog/2015/06/11/react-dot-js-firefox-issue-with-onblur/
*/
);if (element.nativeEvent.explicitOriginalTarget && element.nativeEvent.explicitOriginalTarget == element.nativeEvent.originalTarget) {
if (element.nativeEvent.explicitOriginalTarget && element.nativeEvent.explicitOriginalTarget == element.nativeEvent.originalTarget) {
return;
}
_this.finishEditing();
Expand Down
4 changes: 3 additions & 1 deletion src/RIEStatefulBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export default class RIEStatefulBase extends RIEBase {
if (this.state.editing && !prevState.editing) {
debug('entering edit mode')
inputElem.focus();
this.selectInputText(inputElem);
if (typeof this.props.selectAll === 'undefined' || this.props.selectAll) {
this.selectInputText(inputElem);
}
} else if (this.state.editing && prevProps.text != this.props.text) {
debug('not editing && text not equal previous props -- finishing editing')
this.finishEditing();
Expand Down