-
Notifications
You must be signed in to change notification settings - Fork 18
Conversation
README.md
Outdated
@@ -540,6 +540,26 @@ render( | |||
) | |||
``` | |||
|
|||
## WithAutofillProps (props) (Component) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the w
lowercase as per convention :)
return ( | ||
<article> | ||
<h1>withAutofillProps</h1> | ||
<input placeholder={autofill ? 'autofilled!' : 'not autofilled'} {...props} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this show? Since auto fill will put context inside. Maybe we can change the border color or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also let's put a name='email'
so that the autofill triggers.
src/withAutofillProps.js
Outdated
injectAutofillHook() | ||
|
||
if (window.__klarna_ui_components) { | ||
window.__klarna_ui_components.isAutofillInjected = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s call this magic variable something else, more generic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about __higherOrderComponents__withAutofillProps__wasInjected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rely on document.getElementById(styleElementId) === null
instead?
src/withAutofillProps.spec.js
Outdated
import withAutofillProps from './withAutofillProps' | ||
import { equal } from 'assert' | ||
|
||
describe('withAutofillProps', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so about how to test this more, this is what I would do:
it('has the autofilled prop when autofill animation gets triggered', done => {
const root = document.createElement('div')
let animationStartCallback
function Target ({autoFilled, onAnimationStart}) {
animationStartCallback = onAnimationStart
return <div>{autoFilled ? 'autofilled' : 'not autofilled'}</div>
}
const DecoratedTarget = withAutoFillProps({
autofilled: true,
})(Target)
render(<DecoratedTarget />, root)
equal(root.innerText, 'not autofilled')
animationStartCallback('onAutofillStart')
equal(root.innerText, 'autofilled')
})
…and the equivalent for when the autofilled gets removed ( animationStartCallback('onAutofillStop')
)
This way you don't have to trigger the real autofill to test it, which is of course impossible 😅
injectStyle(notAutofillHook) | ||
} | ||
|
||
function registerAutofill() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have unregisterAutofill
as well?
onComponentDidMount() {
registerAutofill()
}
onComponentWillUnmount() {
unregisterAutofill()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that safe to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... if you have 5 components wrapped with this HOC then you can't just remove <style>
from DOM when one of them is about to unmount. But from another hand it's a dirty side effect which should be cleaned up somehow if nobody is using it anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we need to keep track of how many are using it. In global state. Tricky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it by keeping a counter on the style element instead oh saving it on the window.
No description provided.