CSR-762 Fix merge conflict
This commit is contained in:
parent
00d7fd1611
commit
782dcfd8a6
1 changed files with 42 additions and 0 deletions
42
src/helpers/button-question-focus-helper.js
Normal file
42
src/helpers/button-question-focus-helper.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* Helper for GA click event. When the user mouse clicks on a `base-input-button`, we
|
||||
* push the click event. When the user tabs through a list of radio buttons via a
|
||||
* keyboard, we only want to push the GA click event if the selection was deliberate
|
||||
* (space/enter key) or if there is a selection and the user tabs off of the radio group.
|
||||
*/
|
||||
|
||||
let lastFocusedInputGroupName = "";
|
||||
let onButtonQuestionLostFocusCallback = null;
|
||||
|
||||
// TODO KO add tests
|
||||
const handleAnyComponentFocus = (e) => {
|
||||
const targetType = e.target.type;
|
||||
if (targetType !== "radio" && targetType !== "checkbox") {
|
||||
invokeButtonQuestionLostFocusCallback();
|
||||
}
|
||||
};
|
||||
|
||||
const handleButtonComponentFocus = (e) => {
|
||||
if (e && lastFocusedInputGroupName !== e.groupName) {
|
||||
invokeButtonQuestionLostFocusCallback();
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputComponentBlur = (e) => {
|
||||
if (e) {
|
||||
lastFocusedInputGroupName = e.groupName;
|
||||
onButtonQuestionLostFocusCallback = e.onButtonQuestionLostFocusCallback;
|
||||
}
|
||||
};
|
||||
|
||||
const invokeButtonQuestionLostFocusCallback = () => {
|
||||
if (onButtonQuestionLostFocusCallback) {
|
||||
onButtonQuestionLostFocusCallback();
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
handleAnyComponentFocus,
|
||||
handleButtonComponentFocus,
|
||||
handleInputComponentBlur,
|
||||
};
|
||||
Loading…
Reference in a new issue