Skip to content

Commit

Permalink
feat(tips): add support for heading elements (#1838)
Browse files Browse the repository at this point in the history
  • Loading branch information
saiponnada authored Jan 9, 2023
1 parent cabef6c commit a6a228e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/components/components/ebay-tooltip-overlay/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import constants from "./constants";
static function noop() {}
static var typeRoles = constants.typeRoles;
static var pointerStyles = constants.pointerStyles;
static var ignoredHeaderAttributes = ["id", "as", "class"];

$ input.toJSON = noop;

Expand All @@ -19,28 +20,29 @@ $ var overlayStyles = hasUserStyles ? {
right: input.styleRight,
bottom: input.styleBottom
} : pointerStyles[input.pointer || "bottom"];
$ var heading = input.heading;

<span
id=input.id
class=`${input.type}__overlay`
role=typeRoles[input.type]
aria-labelledby=(
input.type === "tourtip" &&
input.heading &&
heading &&
component.elId("tourtip-label")
)
style=overlayStyles>
<span class=`${input.type}__pointer ${input.type}__pointer--${input.pointer}`/>
<span class=`${input.type}__mask`>
<span class=`${input.type}__cell`>
<span class=`${input.type}__content`>
<if(input.heading)>
<span
...processHtmlAttributes(input.heading)
<if(heading)>
<${heading.as || "span"}
...processHtmlAttributes(heading, ignoredHeaderAttributes)
class=[`${input.type}__heading`, input.heading.class]
id:scoped="tourtip-label">
<${input.heading.renderBody}/>
</span>
<${heading.renderBody}/>
</>
</if>
<if(input.content)>
<${Object.keys(input.content).length > 1 && "span"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
<span
class="tourtip__content"
>
[36m<span[39m
[36m<h2[39m
class="tourtip__heading"
id="s0-@base-0-4-tourtip-label"
>
Important
[36m</span>[39m
[36m</h2>[39m
<p>
This new feature was added.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
<span
class="tourtip__content"
>
[36m<span[39m
[36m<h2[39m
class="tourtip__heading"
id="s0-@base-0-4-tourtip-label"
>
Important
[36m</span>[39m
[36m</h2>[39m
<p>
This new feature was added.
</p>
Expand Down
7 changes: 7 additions & 0 deletions src/components/ebay-tourtip/test/test.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('given the default tourtip', () => {

thenItIsOpen();
thenItCanBeClosed();
thenIthasHeading();
});

function thenItIsOpen() {
Expand All @@ -50,4 +51,10 @@ describe('given the default tourtip', () => {
});
});
}

function thenIthasHeading() {
it('then it has the right heading', () => {
expect(component.getByText('Important').tagName).equal('H2');
});
}
});
1 change: 1 addition & 0 deletions src/components/ebay-tourtip/tourtip.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Standard.args = {
},
heading: {
renderBody: 'Important',
as: 'h2',
},
content: {
renderBody: `<p>This new feature was added.</p>`,
Expand Down

0 comments on commit a6a228e

Please sign in to comment.