Skip to content

Commit

Permalink
fix ability to disable the (less) option
Browse files Browse the repository at this point in the history
  • Loading branch information
tomickigrzegorz committed Aug 5, 2020
1 parent 4b30483 commit b1c8963
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/showMore.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions sources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ShowMore {
this.className = className;
this.typeElement = type || 'span';
this.more = more;
this.less = less || '';
this.less = less || false;
this.showMore = `<span class="show-more show-more-button" aria-label="expand" tabindex="0">${more}</span>`;
this.showLess = `<span class="show-less show-more-button" aria-label="collapse" tabindex="0">${less}</span>`;
this.regex = {
Expand Down Expand Up @@ -158,11 +158,17 @@ class ShowMore {
const lastChildElement = element.lastElementChild;

element.setAttribute('aria-expanded', logic);
target.innerHTML =
button || type === 'table'
? target.parentNode.removeChild(target)
: lastChildElement.parentNode.removeChild(lastChildElement);
target.setAttribute('aria-label', `${expandCollapse} ${ariaLabelText}`);

if (button) {
target.innerHTML = button;
}
if (!button && type === 'table') {
target.parentNode.removeChild(target);
}
if (!button && type === 'list') {
lastChildElement.parentNode.removeChild(lastChildElement);
}
}
}

Expand Down

0 comments on commit b1c8963

Please sign in to comment.