Skip to content

Commit

Permalink
chore(dropdown): change so JS code do not have to mangle arrow icon
Browse files Browse the repository at this point in the history
  • Loading branch information
asudoh committed May 2, 2018
1 parent dac0975 commit 879187f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
9 changes: 3 additions & 6 deletions src/components/dropdown/_dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
}
}

.#{$prefix}--dropdown__arrow,
.#{$prefix}--dropdown-text svg {
.#{$prefix}--dropdown__arrow {
fill: $brand-01;
position: absolute;
right: 1rem;
Expand Down Expand Up @@ -125,8 +124,7 @@
}

.#{$prefix}--dropdown--open {
.#{$prefix}--dropdown__arrow,
.#{$prefix}--dropdown-text svg {
.#{$prefix}--dropdown__arrow {
transform: rotate(-180deg);
}

Expand Down Expand Up @@ -196,8 +194,7 @@
outline: none;
}

.#{$prefix}--dropdown__arrow,
.#{$prefix}--dropdown-text svg {
.#{$prefix}--dropdown__arrow {
position: relative;
top: -2px;
left: 8px;
Expand Down
2 changes: 1 addition & 1 deletion src/components/dropdown/dropdown--inline.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ul data-dropdown data-value data-dropdown-type="inline" class="bx--dropdown bx--dropdown--inline" tabindex="0">
<li class="bx--dropdown-text">
Inline Dropdown label
<span class="bx--dropdown-text__inner">Inline Dropdown label</span>
<svg class="bx--dropdown__arrow" width="10" height="5" viewBox="0 0 10 5" fill-rule="evenodd">
<path d="M10 0L5 5 0 0z"></path>
</svg>
Expand Down
16 changes: 6 additions & 10 deletions src/components/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,13 @@ class Dropdown extends mixin(createComponent, initComponentBySearch, trackBlur)
detail: { item: itemToSelect },
});

const caretHTML = `
<svg width="10" height="5" viewBox="0 0 10 5" fill-rule="evenodd">
<path d="M10 0L5 5 0 0z"></path>
</svg>
`;

if (this.element.dispatchEvent(eventStart)) {
if (this.element.dataset.dropdownType !== 'navigation') {
const text = this.element.querySelector(this.options.selectorText);
if (text && this.element.dataset.dropdownType !== 'inline') {
const selectorText =
this.element.dataset.dropdownType !== 'inline' ? this.options.selectorText : this.options.selectorTextInner;
const text = this.element.querySelector(selectorText);
if (text) {
text.innerHTML = itemToSelect.innerHTML;
} else {
text.innerHTML = `${itemToSelect.innerHTML} ${caretHTML}`;
}
itemToSelect.classList.add(this.options.classSelected);
}
Expand Down Expand Up @@ -197,6 +191,7 @@ class Dropdown extends mixin(createComponent, initComponentBySearch, trackBlur)
* @type {Object}
* @property {string} selectorInit The CSS selector to find selectors.
* @property {string} [selectorText] The CSS selector to find the element showing the selected item.
* @property {string} [selectorTextInner] The CSS selector to find the element showing the selected item, used for inline mode.
* @property {string} [selectorItem] The CSS selector to find clickable areas in dropdown items.
* @property {string} [selectorItemSelected] The CSS selector to find the clickable area in the selected dropdown item.
* @property {string} [classSelected] The CSS class for the selected dropdown item.
Expand All @@ -212,6 +207,7 @@ class Dropdown extends mixin(createComponent, initComponentBySearch, trackBlur)
return {
selectorInit: '[data-dropdown]',
selectorText: `.${prefix}--dropdown-text`,
selectorTextInner: `.${prefix}--dropdown-text__inner`,
selectorItem: `.${prefix}--dropdown-link`,
selectorItemSelected: `.${prefix}--dropdown--selected`,
classSelected: `${prefix}--dropdown--selected`,
Expand Down

0 comments on commit 879187f

Please sign in to comment.