-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(atomic): using
_blank
target on custom recommendation link temp…
…late opens two tabs on click (#4953) [SVCC-4611](https://coveord.atlassian.net/browse/SVCC-4611) When a recommendation list uses a custom link template to open recommendations in a new tab, clicking the recommendation opens two tabs instead of one. **How to reproduce the issue** 1. Override the `atomic-recs-result-template` as [per documentation](https://docs.coveo.com/en/atomic/latest/reference/result-template-components/atomic-result-link/#slots). ```html <atomic-recs-result-template> <template slot="link"> <atomic-result-link> <a slot="attributes" target="_blank"></a> </atomic-result-link> </template> <template>... recommendation content is there ...</template> </atomic-recs-result-template> ``` 2. If you click the content of the recommendation, it open two tabs. If you click the margin (between the border and the content), then it opens a single tab. **Problem** The recommendation list components rely on [DisplayGrid](https://github.com/coveo/ui-kit/blob/master/packages/atomic/src/components/common/item-list/display-grid.tsx) for their rendering. The problem is related to [this line](https://github.com/coveo/ui-kit/blob/master/packages/atomic/src/components/common/item-list/display-grid.tsx#L26) where `DisplayGrid` forces a click on the recommendation content. When the recommendation content overrides the `link` slot, it already has an event handler for the `click`. It means that, when clicking the recommendation content, its `click` handler is invoked (opening the first tab). Then, the event propagates to the parent (`DisplayGrid`) which forces a `click` event on the content, causing another tab to open. **Proposed solution** The proposed solution is to modify the recommendation lists to detect whether the `link` slot is modified. If it is, then the `stopPropagation` property is set on the child `atomic-recs-result` component. It prevents the `click` event from being propagated to the parent when clicking a recommendation content. However, when outside the recommendation content (i.e., the margin), `DisplayGrid` still forces the `click` on the content, opening a single tab. [SVCC-4611]: https://coveord.atlassian.net/browse/SVCC-4611?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
Showing
7 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters