Skip to content

Commit

Permalink
renamed push/pop to add/delete, fixed hyperlink underline
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisakinrinade committed Jun 7, 2021
1 parent 3ca12e9 commit 7b01261
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/ids-breadcrumb/add-remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ button1.onclick = () => {
link.innerText = `Breadcrumb ${breadcrumb.children.length + 1}`;
link.href = '#';
if (checkbox.checked) link.disabled = '';
breadcrumb.push(link);
breadcrumb.add(link);
};

button2.onclick = () => breadcrumb.pop();
button2.onclick = () => breadcrumb.delete();
6 changes: 3 additions & 3 deletions app/ids-breadcrumb/standalone-css.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<link rel="stylesheet" href="../ids-hyperlink/ids-hyperlink.css" />

<div class="ids-breadcrumb" role="list">
<a class="ids-hyperlink ids-text-14" role="listitem" href="#">First Breadcrumb</a>
<a class="ids-hyperlink ids-text-14" role="listitem">Breadcrumb - No href</a>
<a class="ids-hyperlink ids-text-14" role="listitem" disabled href="#">Disabled</a>
<a class="ids-hyperlink ids-text-14" text-decoration="none" role="listitem" href="#">First Breadcrumb</a>
<a class="ids-hyperlink ids-text-14" text-decoration="none" role="listitem">Breadcrumb - No href</a>
<a class="ids-hyperlink ids-text-14" text-decoration="none" role="listitem" disabled href="#">Disabled</a>
</div>

{{> ../layouts/footer.html }}
12 changes: 8 additions & 4 deletions src/ids-breadcrumb/ids-breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class IdsBreadcrumb extends mix(IdsElement).with(IdsEventsMixin, IdsThemeMixin)
#init() {
this.setAttribute('role', 'list');
const stack = [];
while (this.lastElementChild) { stack.push(this.pop()); }
while (stack.length) { this.push(stack.pop()); }
/* istanbul ignore next */
while (this.lastElementChild) { stack.push(this.delete()); }
/* istanbul ignore next */
while (stack.length) { this.add(stack.pop()); }
}

/**
Expand All @@ -54,13 +56,15 @@ class IdsBreadcrumb extends mix(IdsElement).with(IdsEventsMixin, IdsThemeMixin)
* Appends an individual breadcrumb to the end of the stack
* @param {Element} breadcrumb The HTML element with which to add
*/
push(breadcrumb) {
add(breadcrumb) {
if (this.lastElementChild) {
this.lastElementChild.setAttribute('font-weight', '');
}
breadcrumb.setAttribute('font-weight', 'bolder');
breadcrumb.setAttribute('color', 'unset');
breadcrumb.setAttribute('role', 'listitem');
breadcrumb.setAttribute('text-decoration', 'none');
/* istanbul ignore next */
if (!(breadcrumb.getAttribute('font-size'))) {
breadcrumb.setAttribute('font-size', 14);
}
Expand All @@ -71,7 +75,7 @@ class IdsBreadcrumb extends mix(IdsElement).with(IdsEventsMixin, IdsThemeMixin)
* Removes the last breadcrumb from the stack.
* @returns {Element | null} The removed element
*/
pop() {
delete() {
if (this.lastElementChild) {
const breadcrumb = this.removeChild(this.lastElementChild);
if (this.lastElementChild) {
Expand Down
2 changes: 1 addition & 1 deletion src/ids-hyperlink/ids-hyperlink.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
}

a.ids-hyperlink {
[text-decoration='none'] {
text-decoration: none;
}

Expand Down
19 changes: 10 additions & 9 deletions test/ids-breadcrumb/ids-breadcrumb-func-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ describe('IdsBreadcrumb Component', () => {
it('renders with no errors', () => {
const errors = jest.spyOn(global.console, 'error');
const elem = new IdsBreadcrumb();
expect(document.querySelectorAll('ids-breadcrumb').length).toEqual(1);
document.body.appendChild(elem);
elem.remove();
expect(document.querySelectorAll('ids-breadcrumb').length).toEqual(1);
expect(errors).not.toHaveBeenCalled();
});

it('pushes new crumbs onto the stack', () => {
breadcrumb.push(new IdsHyperlink());
breadcrumb.push(new IdsHyperlink());
it('adds new crumbs onto the stack', () => {
breadcrumb.add(new IdsHyperlink());
breadcrumb.add(new IdsHyperlink());
expect(breadcrumb.children.length).toEqual(2);
for (const child of breadcrumb.children) {
expect(child.getAttribute('color')).toEqual('unset');
Expand All @@ -38,15 +39,15 @@ describe('IdsBreadcrumb Component', () => {
expect(breadcrumb.lastElementChild.getAttribute('font-weight')).toEqual('bolder');
});

it('pops breadcrumb off the stack and returns it', () => {
breadcrumb.push(new IdsHyperlink());
breadcrumb.push(new IdsHyperlink());
expect(breadcrumb.pop() instanceof IdsHyperlink).toEqual(true);
it('removes breadcrumb off the stack and returns it', () => {
breadcrumb.add(new IdsHyperlink());
breadcrumb.add(new IdsHyperlink());
expect(breadcrumb.delete() instanceof IdsHyperlink).toEqual(true);
expect(breadcrumb.children.length).toEqual(1);
expect(breadcrumb.lastElementChild.fontWeight).toEqual('bolder');
breadcrumb.pop();
breadcrumb.delete();
expect(breadcrumb.children.length).toEqual(0);
expect(breadcrumb.pop()).toEqual(null);
expect(breadcrumb.delete()).toEqual(null);
});

it('renders correctly', () => {
Expand Down

0 comments on commit 7b01261

Please sign in to comment.