Skip to content

Commit

Permalink
fix clicks for atomic-recs-list and atomic-ipx-recs-list
Browse files Browse the repository at this point in the history
  • Loading branch information
fpbrault authored and dguerinCoveo committed Nov 5, 2024
1 parent 07f0889 commit 98af31a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1187,14 +1187,14 @@ export declare interface AtomicRecsList extends Components.AtomicRecsList {}


@ProxyCmp({
inputs: ['classes', 'content', 'density', 'display', 'imageSize', 'result', 'stopPropagation']
inputs: ['classes', 'content', 'density', 'display', 'imageSize', 'linkContent', 'result', 'stopPropagation']
})
@Component({
selector: 'atomic-recs-result',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['classes', 'content', 'density', 'display', 'imageSize', 'result', 'stopPropagation'],
inputs: ['classes', 'content', 'density', 'display', 'imageSize', 'linkContent', 'result', 'stopPropagation'],
})
export class AtomicRecsResult {
protected el: HTMLElement;
Expand Down
10 changes: 10 additions & 0 deletions packages/atomic/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,11 @@ export namespace Components {
* The InteractiveResult item.
*/
"interactiveResult": RecsInteractiveResult;
/**
* The result link to use when the result is clicked in a grid layout.
* @default - An `atomic-result-link` without any customization.
*/
"linkContent": ParentNode;
"loadingFlag"?: string;
/**
* Internal function used by atomic-recs-list in advanced setups, which lets you bypass the standard HTML template system. Particularly useful for Atomic React
Expand Down Expand Up @@ -8050,6 +8055,11 @@ declare namespace LocalJSX {
* The InteractiveResult item.
*/
"interactiveResult": RecsInteractiveResult;
/**
* The result link to use when the result is clicked in a grid layout.
* @default - An `atomic-result-link` without any customization.
*/
"linkContent"?: ParentNode;
"loadingFlag"?: string;
/**
* Internal function used by atomic-recs-list in advanced setups, which lets you bypass the standard HTML template system. Particularly useful for Atomic React
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ export class AtomicIPXRecsList implements InitializableComponent<RecsBindings> {
this.imageSize
),
content: this.itemTemplateProvider.getTemplateContent(recommendation),
linkContent:
this.itemTemplateProvider.getLinkTemplateContent(recommendation),
store: this.bindings.store,
density: this.density,
display: this.display,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ export class AtomicRecsList implements InitializableComponent<RecsBindings> {
this.imageSize
),
content: this.itemTemplateProvider.getTemplateContent(recommendation),
linkContent:
this.itemTemplateProvider.getLinkTemplateContent(recommendation),
store: this.bindings.store,
density: this.density,
display: this.display,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Component, h, Prop, Element, Listen, Host} from '@stencil/core';
import {RecsInteractiveResult, RecsResult} from '..';
import {parentNodeToString} from '../../../utils/dom-utils';
import {applyFocusVisiblePolyfill} from '../../../utils/initialization-utils';
import {
InteractiveItemContextEvent,
Expand Down Expand Up @@ -29,6 +30,7 @@ import {AtomicRecsStore} from '../atomic-recs-interface/store';
export class AtomicRecsResult {
private layout!: ItemLayout;
private resultRootRef?: HTMLElement;
private linkContainerRef?: HTMLElement;
private executedRenderingFunctionOnce = false;
@Element() host!: HTMLElement;

Expand All @@ -37,6 +39,13 @@ export class AtomicRecsResult {
*/
@Prop() stopPropagation?: boolean;

/**
* The result link to use when the result is clicked in a grid layout.
*
* @default - An `atomic-result-link` without any customization.
*/
@Prop() linkContent: ParentNode = new DocumentFragment();

/**
* The result item.
*/
Expand Down Expand Up @@ -94,6 +103,18 @@ export class AtomicRecsResult {
*/
@Prop() renderingFunction: ItemRenderingFunction;

@Listen('click')
public handleClick(event: MouseEvent) {
if (this.stopPropagation) {
event.stopPropagation();
}
this.host
.shadowRoot!.querySelector<HTMLAnchorElement>(
'.link-container > atomic-result-link a:not([slot])'
)
?.click();
}

@Listen('atomic/resolveResult')
public resolveResult(event: ItemContextEvent<RecsResult>) {
event.preventDefault();
Expand Down Expand Up @@ -133,11 +154,12 @@ export class AtomicRecsResult {
}

private getContentHTML() {
return Array.from(this.content!.children)
.map((child) => child.outerHTML)
.join('');
return parentNodeToString(this.content!);
}

private getLinkHTML() {
return parentNodeToString(this.linkContent);
}
private get isCustomRenderFunctionMode() {
return this.renderingFunction !== undefined;
}
Expand All @@ -158,6 +180,10 @@ export class AtomicRecsResult {
class="result-root"
ref={(ref) => (this.resultRootRef = ref)}
></div>
<div
class="link-container"
ref={(ref) => (this.linkContainerRef = ref)}
></div>
</Host>
);
}
Expand All @@ -171,6 +197,7 @@ export class AtomicRecsResult {
.join(' ')}`}
innerHTML={this.getContentHTML()}
></div>
<div class="link-container" innerHTML={this.getLinkHTML()}></div>
</Host>
);
}
Expand All @@ -186,7 +213,8 @@ export class AtomicRecsResult {
if (this.shouldExecuteRenderFunction()) {
const customRenderOutputAsString = this.renderingFunction!(
this.result,
this.resultRootRef!
this.resultRootRef!,
this.linkContainerRef!
);

this.resultRootRef!.className += ` ${this.layout
Expand Down
1 change: 0 additions & 1 deletion packages/atomic/src/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@
</atomic-result-template>

<atomic-result-template>
<template slot="link"> </template>
<template>
<style>
.field {
Expand Down

0 comments on commit 98af31a

Please sign in to comment.