Skip to content

Commit

Permalink
fix: dropdown value presentation (#873)
Browse files Browse the repository at this point in the history
Co-authored-by: Lee Chase <lee.chase@uk.ibm.com>
  • Loading branch information
lee-chase and lee-chase authored Apr 24, 2020
1 parent 76229c5 commit 1d4ab65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions packages/core/src/components/cv-dropdown/cv-dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
:class="{ 'bx--dropdown__wrapper--inline': inline, 'cv-dropdown': !formItem }"
:style="wrapperStyleOverride"
>
<span v-if="label" :id="`${uid}-label`" class="bx--label" :class="{ 'bx--label--disabled': disabled }">{{
label
}}</span>
<span v-if="label" :id="`${uid}-label`" class="bx--label" :class="{ 'bx--label--disabled': disabled }">
{{ label }}
</span>

<div
v-if="!inline && isHelper"
Expand Down Expand Up @@ -65,7 +65,12 @@
type="button"
>
<WarningFilled16 v-if="isInvalid && inline" class="bx--dropdown__invalid-icon" />
<span class="bx--dropdown-text__inner" :id="`${uid}-value`">{{ internalCaption }}</span>
<span
class="bx--dropdown-text__inner"
:id="`${uid}-value`"
data-test="internalCaption"
v-html="internalCaption"
/>
<span class="bx--dropdown__arrow-container">
<span class="bx--dropdown__arrow" :style="chevronStyleOveride">
<chevron-down-glyph />
Expand All @@ -79,6 +84,7 @@
:aria-hidden="!open"
wh-menu-anchor="left"
:aria-labelledby="`${uid}-label`"
ref="droplist"
>
<slot></slot>
</ul>
Expand Down Expand Up @@ -281,8 +287,13 @@ export default {
this.$el.focus();
}
if (ev.target.classList.contains('bx--dropdown-link')) {
const targetItemEl = ev.target.parentNode;
let target = ev.target;
while (!target.classList.contains('bx--dropdown-link') && this.$refs.droplist.contains(target)) {
target = target.parentNode; // try next one up
}
if (target.classList.contains('bx--dropdown-link')) {
const targetItemEl = target.parentNode;
const newValue = targetItemEl.getAttribute('data-value');
this.internalValue = newValue;
Expand Down
2 changes: 1 addition & 1 deletion storybook/stories/cv-dropdown-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ for (const story of storySet) {

const templateString = `
<cv-dropdown ${settings.group.attr}>${settings.group.slots}
<cv-dropdown-item value="10">Option with value 10</cv-dropdown-item>
<cv-dropdown-item value="10"><span>Option with value 10 & 10.0</span></cv-dropdown-item>
<cv-dropdown-item value="20">Option with value 20</cv-dropdown-item>
<cv-dropdown-item value="30">Option with value 30</cv-dropdown-item>
<cv-dropdown-item value="40">Option with value 40</cv-dropdown-item>
Expand Down

0 comments on commit 1d4ab65

Please sign in to comment.