Skip to content

Commit

Permalink
Navigation: Open Original Url On Click (#1802)
Browse files Browse the repository at this point in the history
Now, when a Navigation component's parentUrl is set, clicking on the link will still
open the original url with target="_self" instead of target="_parent".

This ensures that when a link is clicked on from within an iframe, the link will only cause the iframe
to refresh, and not the parent frame.

J=SLAP-2638
TEST=manual

hook up my local SDK to a local copy of the ufc answers experience 
See that clicking navigation links works without triggering full page reloads
see that a new tab is still opened when I cmd + click
see that middle click still opens a new tab
  • Loading branch information
oshi97 committed Feb 22, 2023
1 parent 85adeb0 commit 4fc4803
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ui/components/navigation/navigationcomponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ export default class NavigationComponent extends Component {
this.refitNav();
DOM.on(DOM.query(this._container, '.yxt-Nav-more'), 'click', this.toggleMoreDropdown.bind(this));
}
const navLinks = DOM.queryAll(this._container, '[data-originalurl]');
navLinks.forEach(link => {
const originalUrl = link.dataset.originalurl;
if (originalUrl) {
DOM.on(link, 'click', e => {
if (e.metaKey || e.ctrlKey) {
return;
}
e.preventDefault();
window.open(originalUrl, '_self');
});
}
});
}

setParentUrl (parentUrl) {
Expand Down Expand Up @@ -389,6 +402,7 @@ export default class NavigationComponent extends Component {
const parentUrlWithoutParams = this._parentUrl.split('?')[0];
const urlParser = document.createElement('a');
tabs.forEach(tab => {
tab.originalUrl = tab.url;
urlParser.href = tab.url;
const tabParams = new SearchParams(urlParser.search);
const verticalUrl = urlParser.pathname.replace(/^\//, '');
Expand Down
3 changes: 3 additions & 0 deletions src/ui/templates/navigation/navigation.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
data-eventtype="VERTICAL_TAB_NAVIGATION"
data-eventoptions='{"verticalKey": "{{verticalKey}}"}'
{{/if}}
{{#if originalUrl}}
data-originalurl="{{originalUrl}}"
{{/if}}
>
{{label}}
</a>
Expand Down

0 comments on commit 4fc4803

Please sign in to comment.