-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Query element by selector later if it's not exists during configuration #1679
base: master
Are you sure you want to change the base?
Query element by selector later if it's not exists during configuration #1679
Conversation
When creating list of steps, we take into account the possible absence of element by selector If .element is a selector for which there is no element at the configuration stage, then we replace .element specifying a getter/setter for it. In the getter we return the element via document.querySelector Since that moment we assume that .element should return HTMLElement by selector and if there is still not element - throwing Error. Thus to check raw field below we need use ._element
And it's not finished yet. If element is added with delay (for example, after async request to server), an error will occur |
Fixed commit b61ffab and added test gooddaytoday@8716a1a for that error |
6446dd6
to
43146e2
Compare
Previously, if you press right arrow button at the end of tour, it ends. Now it doesn't ends and any action after right arrow do nothing
7930cd6
to
7580560
Compare
Rebased and edited branch in order to:
|
try { | ||
const element = steps[0].element; // jshint ignore:line | ||
} catch (e) { | ||
if (!e.message.includes("There is no element with given selector:")) | ||
throw e; | ||
} |
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.
Are we checking here to make sure the steps array is empty?
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.
No, we calling here .element
of the first array item to check that Error "There is not element..." is throwing in case of element absence.
} else { | ||
// If element is not exists yet, we'll get it on step | ||
const elSelector = currentItem.element; | ||
Object.defineProperty(currentItem, "element", { |
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 it important to have this object when the DOMElement doesn't exist? Can we just replace it with undefined
?
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.
Yes, my first (local) implementation was with undefined
, but it could be more changes in other code, that calls .element
.
I'll try to do with undefined
.
src/util/waitForElement.js
Outdated
} | ||
|
||
if (typeof MutationObserver !== "undefined") { | ||
/* jshint ignore:start */ |
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.
Why are we suppressing jshint errors? Happy to help if there are any issues with our jshint setup
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.
Yep, it could be deleted. Added MutationObserver to globals in jshint config and removed jshint ignore gooddaytoday@33e560b
src/util/waitForElement.js
Outdated
* @param {number} checkInterval In milliseconds | ||
* @param {number} maxTimeout In milliseconds | ||
*/ | ||
function waitForElementByTimeout( |
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 test this function please? I'm a little concerned since it's doing a recursive call.
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.
Added tests in gooddaytoday@d5eaf0d
@@ -47,6 +47,14 @@ context("Navigation", () => { | |||
cy.get(".introjs-showElement").should("not.exist"); | |||
}); | |||
|
|||
it("should exit the tour after right btn pressed at the end", () => { | |||
cy.get(".introjs-tooltiptext").contains("step one"); |
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.
Beautiful! Thank you
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.
In fact, there wasn't such error in master before adding this feature. Possible error was taken into account in 87fa604
9db181e
to
6c25ffa
Compare
6c25ffa
to
d5eaf0d
Compare
I'm sorry I didn't wait for approval #1674 🏎️ . Just need to buy commercial license with this feature 🙂 .
Processing possible absence of an element, configured with string selector: when creating list of steps, we take into account the possible absence of element.
step.element
is a selector for which there is no element at the configuration stage, then we replace.element
specifying a getter/setter for it. In the getter we return the element viadocument.querySelector
.element
should returnHTMLElement
by selector and if there is still no element - throwingError
. Thus to check raw field below we need use also._element
.The behavior has changed: earlier if there wasn't element by selector, IntroJS silently created floating tooltip at that step.
Also:
Closes #1674.