Skip to content

Commit

Permalink
fix(icon-button): icon not showing when using ripple (#516)
Browse files Browse the repository at this point in the history
* fix(icon-button): icon not showing when using ripple

Co-authored-by: Simeon Simeonoff <sim.simeonoff@gmail.com>
  • Loading branch information
didimmova and simeonoff authored Sep 29, 2022
1 parent 5e73bc5 commit 5b7e106
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 64 deletions.
67 changes: 28 additions & 39 deletions src/components/button/icon-button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,36 @@ describe('IconButton component', () => {

it('renders a button element internally', async () => {
await expect(el).shadowDom.to.be.accessible();
expect(el).shadowDom.to.equal(
`<button><slot><igc-icon></igc-icon></slot></button>`,
{
ignoreAttributes: [
'variant',
'aria-label',
'aria-disabled',
'aria-hidden',
'part',
'role',
'size',
],
}
);
expect(el).shadowDom.to.equal(`<button><slot></slot></button>`, {
ignoreAttributes: [
'variant',
'aria-label',
'aria-disabled',
'aria-hidden',
'part',
'role',
'size',
],
});
});

it('renders an anchor element internally', async () => {
el.href = 'https://test.com';
await elementUpdated(el);

await expect(el).shadowDom.to.be.accessible();
expect(el).shadowDom.to.equal(
`<a><slot><igc-icon></igc-icon></slot></a>`,
{
ignoreAttributes: [
'variant',
'aria-label',
'aria-disabled',
'aria-hidden',
'part',
'role',
'size',
'href',
],
}
);
expect(el).shadowDom.to.equal(`<a><slot></slot></a>`, {
ignoreAttributes: [
'variant',
'aria-label',
'aria-disabled',
'aria-hidden',
'part',
'role',
'size',
'href',
],
});
});

it('is created with the proper default values', async () => {
Expand All @@ -82,9 +76,8 @@ describe('IconButton component', () => {

expect(el).shadowDom.to.equal(
`<button>
<slot>
<igc-icon name="${el.name}" collection="${el.collection}"></igc-icon>
</slot>
<igc-icon name="${el.name}" collection="${el.collection}"></igc-icon>
<slot></slot>
</button>`,
{
ignoreAttributes: [
Expand All @@ -106,9 +99,8 @@ describe('IconButton component', () => {

expect(el).shadowDom.to.equal(
`<button>
<slot>
<igc-icon mirrored></igc-icon>
</slot>
<igc-icon mirrored></igc-icon>
<slot></slot>
</button>`,
{
ignoreAttributes: [
Expand Down Expand Up @@ -171,7 +163,6 @@ describe('IconButton component', () => {
expect(el).shadowDom.to.equal(
`<button disabled>
<slot>
<igc-icon></igc-icon>
</slot>
</button>`,
{
Expand Down Expand Up @@ -204,9 +195,7 @@ describe('IconButton component', () => {
);
expect(el).shadowDom.to.equal(
`<a href="https://test.com" target="_blank" download="test" rel="test">
<slot>
<igc-icon name="biking" collection="default"></igc-icon>
</slot>
<igc-icon name="biking" collection="default"></igc-icon>
</a>`,
DIFF_OPTIONS
);
Expand Down
23 changes: 13 additions & 10 deletions src/components/button/icon-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@ export default class IgcIconButtonComponent extends IgcButtonBaseComponent {

protected renderContent() {
return html`
<slot>
<igc-icon
part="icon"
name=${ifDefined(this.name)}
collection=${ifDefined(this.collection)}
.mirrored=${this.mirrored}
size=${ifDefined(this.size)}
aria-hidden="true"
></igc-icon>
</slot>
${this.name || this.mirrored
? html`
<igc-icon
part="icon"
name=${ifDefined(this.name)}
collection=${ifDefined(this.collection)}
.mirrored=${this.mirrored}
size=${ifDefined(this.size)}
aria-hidden="true"
></igc-icon>
<slot></slot>
`
: html`<slot></slot>`}
`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
vertical-align: middle;
}

::slotted(*) {
::slotted(:not(igc-ripple)) {
font-size: var(--size) !important;
vertical-align: middle;
}

slot {
pointer-events: none;
}

// This prevents the igc-ripple from working.
// slot {
// pointer-events: none;
// }

[part='base'] {
@include border-radius(50%);

Expand Down
17 changes: 6 additions & 11 deletions stories/icon-button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ const Template: Story<ArgTypes, Context> = (
variant=${ifDefined(variant)}
.size=${size}
.disabled=${ifDefined(disabled)}
></igc-icon-button>
>
<igc-ripple></igc-ripple>
</igc-icon-button>
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
Expand All @@ -163,9 +165,6 @@ const Template: Story<ArgTypes, Context> = (
rel="stylesheet"
/>
<igc-icon-button
.name=${name}
.collection=${collection}
.mirrored=${mirrored}
href=${ifDefined(href)}
target=${ifDefined(target)}
rel=${ifDefined(rel)}
Expand All @@ -174,12 +173,11 @@ const Template: Story<ArgTypes, Context> = (
variant=${ifDefined(variant)}
.size=${size}
.disabled=${ifDefined(disabled)}
>💙</igc-icon-button
>
<igc-ripple></igc-ripple>
💙
</igc-icon-button>
<igc-icon-button
.name=${name}
.collection=${collection}
.mirrored=${mirrored}
href=${ifDefined(href)}
target=${ifDefined(target)}
rel=${ifDefined(rel)}
Expand All @@ -192,9 +190,6 @@ const Template: Story<ArgTypes, Context> = (
<span class="material-icons">favorite</span>
</igc-icon-button>
<igc-icon-button
.name=${name}
.collection=${collection}
.mirrored=${mirrored}
href=${ifDefined(href)}
target=${ifDefined(target)}
rel=${ifDefined(rel)}
Expand Down

0 comments on commit 5b7e106

Please sign in to comment.