-
Notifications
You must be signed in to change notification settings - Fork 41
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
Uninitialises after focus on yoked text input #27
Comments
Note: Once this behaviour is triggered it is carried over to any other component that is newly mounted henceforth e.g. when you transition to a new route and mount a new component the fastClick is still absent |
I'm out of the country at the moment, and don't have access to a computer, but if you can give me a little more info I'll have a think about it before I get back (in a couple of days). Apart from the lack of fastclick, does everything else function correctly? Click and change events firing etc? Can you see if there are any errors? You'll have to use the Safari debug tools to check with an iPhone. Can you check if this problem persists for other devices? I'd recommend using the Chrome dev tools in device mode. Could you post an example of the mark-up for your labels and inputs (the checkbox and text input). So I can see how they are related. E.g. what are child elements/siblings and if they are using htmlFor, etc. |
Hi Jake sorry for the delay. Here are the answers:
|
"dependencies": {
"amazeui-touch": "^1.0.0-beta.1",
"babel-eslint": "^6.0.4",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-regenerator-runtime": "^6.5.0",
"classnames": "^2.2.5",
"css-loader": "^0.23.1",
"file-loader": "^0.8.5",
"html-webpack-plugin": "^2.16.1",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-fastclick": "^2.1.1",
"react-redux": "^4.4.5",
"react-router": "^2.4.0",
"react-router-redux": "^4.0.4",
"redux": "^3.5.2",
"redux-logger": "^2.6.1",
"redux-promise": "^0.5.3",
"redux-thunk": "^2.1.0",
"style-loader": "^0.13.1",
"stylus": "^0.54.5",
"stylus-loader": "^2.0.0",
"url-loader": "^0.5.7",
"webpack": "^1.13.0"
},
"devDependencies": {
"webpack-dev-server": "^1.14.1",
"eslint": "^2.9.0",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-babel": "^3.2.0",
"eslint-plugin-import": "^1.8.0",
"eslint-plugin-jsx-a11y": "^1.2.0",
"eslint-plugin-markdown": "^1.0.0-beta.2",
"eslint-plugin-react": "^5.1.1"
}, $ node -v
v5.7.1
$ npm -v
3.6.0 |
When you say you don't get fastclicks on Android devices, do you mean that the event.fastclick property is not defined? As there should be no delay on Android devices anyway (as far as I know). Seems that is could be due to React preventing setting event properties in 0.15. I'll test this out myself tonight and see if I can fix it. Seems that event.persist() could do the trick. Thanks for all your help. :) |
Hi Jake, no worries - please note I'm using react 0.14. The package.json posted above is not mine :) When i say no fast clicks on Android I'm basing purely on what i see when I click i.e. there is a delay on the click, its not based on evidence as such |
Oh, woops. Was on my mobile, hard to see everything on such a small screen. XD Thanks you all for your help in that case. I'll have a look at both 0.14 and 0.15. Seems like 0.15 at least should be a reasonably easy fix. :) P.s. 2 GitHub accounts? |
Yes 2 Github accounts! On 16 May 2016 at 22:04, Jake [email protected] wrote:
|
@yinzSE Would you mind opening another issue with the information you've posted above. Appears to be related specifically to React |
@leanne-tite-jg / @leanne1 I can't seem to reproduce the problem you're having with React Could you add some onClick handlers (I'd suggest keeping these in a separate branch as I may need to get some more info following the results) to the input and buttons like the following: handleClick: function (event) {
console.log(event.type, event.fastclick);
}
<input onClick={this.handleClick} /> And let me know what the outcome is when clicking on a few of them?
My current thought is that there may be a memory leak somehow in your app, or react-fastclick, or something else causing slow rendering. Should get a rough idea from the results of that handler. :) |
Hi Jake I've done as the above and here are the results: 1. Radio input ('button') - note that clicks do not fire as the radio is hidden and the click is on the label. Clicking the label fires an
2. When i click the text input that triggers the bug i get:
3. When i click the buttons again following clicking in the input i get (so basically no change, even though the fast click is visibly missing):
However, I have thought of what might be an issue here. The UI components on the page (radio group, text input with currency prefix) are imported from our own UI library. The UI library contains CSS and, for some elements, also JS enhancements. The JS enhancements are pure OOJS. So for example, the text input you see is enhanced with JS that handles changing the currency prefix. The JS enhancements on this inout are instantiated and handled within the React component as: /**
* Initialise input prefix
*/
componentDidMount() {
const { inputPrefix, id } = this.props;
if (inputPrefix) {
this.inputPrefix = new DNAInputPrefix({
el: this.refs[id]
});
}
}
/**
* Update input prefix
*/
componentDidUpdate(prevProps) {
if (prevProps.inputPrefix !== this.props.inputPrefix) {
this.inputPrefix.updatePrefix();
}
}
/**
* Destroy input prefix
*/
componentWillUnmount() {
if (this.inputPrefix) {
this.inputPrefix = null;
}
} So effectively this code short-circuits React. The import {emitter} from 'dna-core/components/eventemitter';
/**
* Class representing a dna input-prefix
* @classdesc Constructor for a dna input-prefix
* @param {Object} options.el. Class instance's parent element
*/
export default class InputPrefix {
constructor(options = {}) {
this.el = options.el;
// Cancel instantiation if DOM not as expected
if (!this.verifyDOM()) {
emitter.emit('dna.InputPrefix.didCancelInit', {
emitter: this
});
return {};
}
this.init();
// Everything inited as expected
emitter.emit('dna.InputPrefix.didInit', {
emitter: this
});
return this;
}
/**
* Verify the required DOM nodes are present
* @description Check that the object instance's parent element, and any necessary child nodes, are present in the DOM
* @returns {Boolean} Whether all DOM nodes are present or not
*/
verifyDOM() {
let hasVerified = true;
if (!this.el || !this.el.hasAttribute('data-dna-input-prefix')) {
hasVerified = false;
}
return hasVerified;
}
/**
* Initialise the class
* @description
*/
init() {
this.inputPadding = parseInt(getComputedStyle(this.el).paddingLeft, 10);
this.wrapInput();
this.createTokenEl();
this.appendToken();
this.setPrefix();
}
/**
* Create wrapper around input
*/
wrapInput() {
if (!this.el.parentNode.classList.contains('dna-input-prefix')) {
this.wrapper = document.createElement('span');
this.wrapper.classList.add('dna-input-prefix');
this.el.parentNode.insertBefore(this.wrapper, this.el);
this.wrapper.appendChild(this.el);
}
}
/**
* Create element to hold prefix
*/
createTokenEl() {
this.token = document.createElement('span');
this.token.classList.add('dna-input-prefix-token');
}
/**
* Append the prefix token to the input wrapper
*/
appendToken() {
this.wrapper.appendChild(this.token);
}
setPrefix() {
this.setTokenLabel();
this.getPrefixWidth();
this.setInputPadding();
}
/**
* Set the text (label) of the prefix token to the data-dna-input-prefix value
*/
setTokenLabel() {
this.token.innerHTML = this.el.dataset.dnaInputPrefix;
}
/**
* Get the computed width of the label
*/
getPrefixWidth() {
return this.token.offsetWidth;
}
/**
* Set padding on the input to account for prefix width plus its own padding
*/
setInputPadding() {
this.el.style.paddingLeft = `${this.inputPadding + this.getPrefixWidth()}px`;
}
/**
* Reset the prefix label to latest data-dna-input-prefix value
*/
updatePrefix() {
this.setTokenLabel();
this.setInputPadding();
}
} However, notice that none of methods get invoked just from focusing the input, and indeed a log in React do say that you can use third-party library code in a react component by directly accessing a DOM Node with |
Hard to say from a quick look, if this could be what's causing the delay... but I would say however, that although React states that you can access DOM nodes using refs, you should not mutate the DOM. I've had problems with similar things before. I'm positive that what you're trying to achieve could be done in a much more React friendly way. One possible fix could be to A few questions: |
To answer the questions:
|
Ah, that's a tough one. Would like to help if I can though. I'd recommend returning false from the <InputPrefix element="this.refs.element" /> If returning false from Also, I'm not sure that setting Other than those, all I can suggest is digging through the debugger to see if you can find anything that is being called repeatedly. Or, if the prefix / other components are updating late due to the React components not updating until a request has completed, or something similar. |
I will update the class to include a destroy method and experiment with your suggestions on handling the updates. Ultimately we might opt to make React versions of these later. Thanks for all your help |
No problem. I'm going to leave the issue open in case it does turn out to be react-fastclick related, but from the info you've provided so far, it does not seem to be. Let me know, here, if you manage to solve this. Then I can close this issue, and as a side, it'd be nice to know how to fix such a problem. :) |
I've added react-fastClick to a React form-based app. We hd the same issue as in #22 and removed the plugin until this issue was fixed. Since adding it back we have noticed the following behaviour on iPhone iOS 9.3.1 Safari (but I'm not sure this issue is device-specific):
I am initialising fastClick with:
on
index.js
which contains a root component which renders the react router routes (on one of which the above behaviour is manifested) and does all the other set up. This root component is in turn rendered. So basically we are initialising react-fastClick at the very top of the application.The text was updated successfully, but these errors were encountered: