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

Fixes #1425 Add target property to dropdown links (API ADDED) #1426

Merged
merged 5 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion packages/clay-dropdown/demos/a11y.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,19 @@ <h2>Creation Menu Dropdown with two groups of secondary items</h2>
**/
new metal.ClayDropdown(
{
itemsIconAlignment: 'left',
items: [
{
label: 'Link 1',
href: '#mylink',
href: '#mylink1',
icon: 'shortcut',
target: '_blank',
type: 'item',
},
{
label: 'Link 2',
href: '#mylink2',
target: '_self',
type: 'item',
},
],
Expand Down
11 changes: 10 additions & 1 deletion packages/clay-dropdown/demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,19 @@ <h2>Creation Menu Dropdown with two groups of secondary items</h2>
**/
new metal.ClayDropdown(
{
itemsIconAlignment: 'left',
items: [
{
label: 'Link 1',
href: '#mylink',
href: '#mylink1',
icon: 'shortcut',
target: '_blank',
type: 'item',
},
{
label: 'Link 2',
href: '#mylink2',
target: '_self',
type: 'item',
},
],
Expand Down
1 change: 1 addition & 0 deletions packages/clay-dropdown/src/ClayDropdownBase.soy
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
{param maxItems: $item.maxItems /}
{param separator: $item.separator /}
{param spritemap: $spritemap /}
{param target: $item.target /}
{param title: $item.title /}
{/call}

Expand Down
9 changes: 9 additions & 0 deletions packages/clay-dropdown/src/ClayDropdownItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ ClayDropdownItem.STATE = {
*/
spritemap: Config.string(),

/**
* Sets the HTML attribute target on the anchor tag.
* @default undefined
* @instance
* @memberof ClayDropdownItem
* @type {?(string|undefined)}
*/
target: Config.oneOf(['_blank', '_self']),

/**
* Title of the item.
* @default undefined
Expand Down
9 changes: 9 additions & 0 deletions packages/clay-dropdown/src/ClayDropdownItem.soy
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{@param? maxItems: int}
{@param? separator: bool}
{@param? spritemap: string}
{@param? target: string}
{@param? title: string}

{let $variant: $contentRenderer ?: 'item' /}
Expand All @@ -38,6 +39,7 @@
{param maxItems: $maxItems /}
{param separator: $separator /}
{param spritemap: $spritemap /}
{param target: $target /}
{param title: $title /}
{/delcall}
{/template}
Expand All @@ -60,6 +62,7 @@
{@param? maxItems: int}
{@param? separator: bool}
{@param? spritemap: string}
{@param? target: string}
{@param? title: string}

{let $itemContent kind="html"}
Expand Down Expand Up @@ -109,6 +112,7 @@
{/param}

{param label: $labelContent /}
{param target: $target /}
{param title: $title /}
{/call}
{else}
Expand Down Expand Up @@ -152,6 +156,7 @@
{@param? maxItems: int}
{@param? separator: bool}
{@param? spritemap: string}
{@param? target: string}
{@param? title: string}

{let $checkbox kind="html"}
Expand Down Expand Up @@ -199,6 +204,7 @@
{@param? maxItems: int}
{@param? separator: bool}
{@param? spritemap: string}
{@param? target: string}
{@param? title: string}

{if $label and $label != ''}
Expand Down Expand Up @@ -236,6 +242,7 @@
{@param? maxItems: int}
{@param? separator: bool}
{@param? spritemap: string}
{@param? target: string}
{@param? title: string}

{let $radio kind="html"}
Expand Down Expand Up @@ -285,6 +292,7 @@
{@param? maxItems: int}
{@param? separator: bool}
{@param? spritemap: string}
{@param? target: string}
{@param? title: string}

{if $label and $label != ''}
Expand Down Expand Up @@ -327,6 +335,7 @@
{@param? maxItems: int}
{@param? separator: bool}
{@param? spritemap: string}
{@param? target: string}
{@param? title: string}

<li aria-hidden="true" class="dropdown-divider" role="presentation"></li>
Expand Down
24 changes: 23 additions & 1 deletion packages/clay-dropdown/src/__tests__/ClayDropdownBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('ClayDropdownBase', function() {
expect(clayDropdownBase).toMatchSnapshot();
});

it('should render a dropdown with trigger szie', () => {
it('should render a dropdown with trigger size', () => {
clayDropdownBase = new ClayDropdownBase({
items: [
{
Expand Down Expand Up @@ -147,6 +147,28 @@ describe('ClayDropdownBase', function() {
expect(clayDropdownBase).toMatchSnapshot();
});

it('should render a dropdown with items of type item with target', () => {
clayDropdownBase = new ClayDropdownBase({
items: [
{
href: 'item1url',
label: 'Item 1',
target: '_self',
title: 'title1',
},
{
href: 'item2url',
label: 'Item 2',
target: '_blank',
title: 'title2',
},
],
label: 'Trigger',
});

expect(clayDropdownBase).toMatchSnapshot();
});

it('should render a dropdown with items of type item and active', () => {
clayDropdownBase = new ClayDropdownBase({
items: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,22 @@ exports[`ClayDropdownBase should render a dropdown with items of type item and d
</div>
`;

exports[`ClayDropdownBase should render a dropdown with items of type item with target 1`] = `
<div class="dropdown">
<button aria-expanded="false" aria-haspopup="true" aria-label="toggle" class="dropdown-toggle btn btn-unstyled" ref="triggerButton" type="button">Trigger</button>
</div>
<div class="dropdown-menu" ref="menu">
<ul class="list-unstyled">
<li tabindex="-1">
<a class=" dropdown-item" href="item1url" target="_self" title="title1">Item 1</a>
</li>
<li tabindex="-1">
<a class=" dropdown-item" href="item2url" target="_blank" title="title2">Item 2</a>
</li>
</ul>
</div>
`;

exports[`ClayDropdownBase should render a dropdown with items of type item with title 1`] = `
<div class="dropdown">
<button aria-expanded="false" aria-haspopup="true" aria-label="toggle" class="dropdown-toggle btn btn-unstyled" ref="triggerButton" type="button">Trigger</button>
Expand Down Expand Up @@ -586,7 +602,7 @@ exports[`ClayDropdownBase should render a dropdown with trigger custom classes 1
</div>
`;

exports[`ClayDropdownBase should render a dropdown with trigger szie 1`] = `
exports[`ClayDropdownBase should render a dropdown with trigger size 1`] = `
<div class="dropdown">
<button aria-expanded="false" aria-haspopup="true" aria-label="toggle" class="dropdown-toggle btn my-cutsom-class btn-unstyled" ref="triggerButton" type="button">Trigger</button>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/clay-dropdown/src/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let itemShape = {
label: Config.oneOfType([Config.number(), Config.string()]),
maxItems: Config.number(),
separator: Config.bool().value(false),
target: Config.oneOf(['_blank', '_self']),
title: Config.string(),
type: Config.oneOf([
'checkbox',
Expand Down