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

fix(card): arrow direction on RTL #12068

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions packages/web-components/src/components/card/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TemplateResult, html, LitElement } from 'lit';
import { property, query, state } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import ArrowRight20 from '@carbon/web-components/es/icons/arrow--right/20.js';
import ArrowLeft20 from '@carbon/web-components/es/icons/arrow--left/20.js';
import CDSLink from '@carbon/web-components/es/components/link/link.js';
import markdownToHtml from '@carbon/ibmdotcom-utilities/es/utilities/markdownToHtml/markdownToHtml.js';
import { carbonElement as customElement } from '@carbon/web-components/es/globals/decorators/carbon-element.js';
Expand Down Expand Up @@ -238,6 +239,24 @@ class C4DCard extends CTAMixin(StableSelectorMixin(CDSLink)) {
`;
}

/**
* @returns The CTA arrow.
*
*/
protected _renderArrow() {
const isLTR =
window.getComputedStyle(this).direction.toUpperCase() === 'LTR';
return html`
<a
class="${`${prefix}--card__link`}"
part="link"
href="${ifDefined(this.href)}"
aria-label="${this.querySelector(`${c4dPrefix}-card-heading`)
?.textContent || ''}"
>${isLTR ? ArrowRight20() : ArrowLeft20()}</a
>
`;
}
/**
* The color scheme.
* A typical use case of using another color scheme of card is having a "CTA" purpose of card at the last in card group.
Expand Down Expand Up @@ -425,19 +444,12 @@ class C4DCard extends CTAMixin(StableSelectorMixin(CDSLink)) {
this._handleVideoTitleUpdate
);
}

render() {
return this._hasPictogram
? html`
<div part="container">
${this._renderInner()}
<a
class="${`${prefix}--card__link`}"
part="link"
href="${ifDefined(this.href)}"
aria-label="${this.querySelector(`${c4dPrefix}-card-heading`)
?.textContent || ''}"
>${ArrowRight20()}</a
>
${this._renderInner()} ${this._renderArrow()}
</div>
`
: html` <div part="container">${this._renderInner()}</div> `;
Expand Down
Loading