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

close autocomplete on click in parent window #1034

Merged
merged 1 commit into from
Jan 14, 2022

Conversation

yen-tt
Copy link
Contributor

@yen-tt yen-tt commented Jan 14, 2022

close autocomplete on click in parent window by sending message from parent window to iframe using iFrameResizer library

in iframe-common.js, run by parent page, add an event listener to the document for click event. When trigger, check if the event is trusted (invoke by user, not external script) and send a message to iframe. In html.hbs, run by iframe, modify onMessage function in iframeResizer to check for message that contains event type 'click'. If so, get all active autocomplete components and invoke their close function.

J=SLAP-1182
TEST=manual

host a site in SGS with a page that uses iframe.js from localhost port (with the pr changes) for cross-origin test. Also modify page to have multiple search bar. See that autocomplete closes when click outside of iframe.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.005%) to 8.823% when pulling cfa4adc on dev/close-autocomplete-outside-iframe into 8e575d9 on develop.

@@ -145,6 +145,10 @@
HitchhikerJS.RuntimeConfigReceiver.handle(message.runtimeConfig);
} else if (window.isOverlay) {
window.Overlay.onMessage(message);
} else if (message.eventType && message.eventType === 'click') {
ANSWERS.components._activeComponents
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oshi97 or @tmeyer2115 , I'm wondering how you all feel about using ANSWERS.components._activeComponents since it's a private property. Alternatively, we could add a public function to the SDK which would allow us to get all of autocomplete components

@@ -145,6 +145,10 @@
HitchhikerJS.RuntimeConfigReceiver.handle(message.runtimeConfig);
} else if (window.isOverlay) {
window.Overlay.onMessage(message);
} else if (message.eventType && message.eventType === 'click') {
ANSWERS.components._activeComponents
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make a method under ANSWERS.components called getByName. That way, we don't leak private, implementation details here. But, that's beyond this scope of this PR. I'll make a separate item to address.

@yen-tt yen-tt merged commit 0b98ab3 into develop Jan 14, 2022
@yen-tt yen-tt deleted the dev/close-autocomplete-outside-iframe branch January 14, 2022 20:25
@tmeyer2115 tmeyer2115 mentioned this pull request Feb 8, 2022
tmeyer2115 added a commit that referenced this pull request Feb 8, 2022
### Features
- Multi-lang versions of the `document-standard` result card and the `documentsearch-standard` direct answer card have been added. (#1041, #1039)
- We automatically bump the `sdkVersion` in the `global_config` on upgrade. (#1031)

### Changes
- RTF styling was added to the `event-standard`, `faq-accordion`, and `location-standard` cards. (#1037)
- The default `universalSectionTemplate` for a `vertical-grid` page was updated to `grid-three-columns`. (#1038)

### Bugfixes
- When clicking outside the iFrame'd experience, the query suggestions dropdown now closes. (#1034)
- There was a bug with the custom `card` command. If the new card's name contained the name of the forked card, the former would not be added properly. This is now fixed. (#1036)
- Previously, if there was a Map on the Universal page, a user could get stuck on the Map while scrolling down the page. This has been fixed. (#1030, #1042)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants