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

Adding slot for arrow icon #473

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions docs/components/DocSlots.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
name: 'after-list',
props: '-',
description: `Slot showed after the menu list.`,
}, {
name: 'arrow-icon',
props: '-',
description: `Slot for a custom arrow icon.`,
} ],
}),
}
Expand Down
17 changes: 15 additions & 2 deletions src/components/Control.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,31 @@
)
},

renderArrow() {
getArrow() {
const { instance } = this
const arrowIconRenderer = instance.$scopedSlots['arrow-icon']

const arrowClass = {
'vue-treeselect__control-arrow': true,
'vue-treeselect__control-arrow--rotated': instance.menu.isOpen,
'vue-treeselect__control-arrow--custom': arrowIconRenderer,
}

if (arrowIconRenderer) {
return (
<div class={arrowClass}> { arrowIconRenderer() }</div>

Check warning on line 83 in src/components/Control.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Control.vue#L82-L83

Added lines #L82 - L83 were not covered by tests
)
}

return <ArrowIcon class={arrowClass} />
},

renderArrow() {
if (!this.shouldShowArrow) return null

return (
<div class="vue-treeselect__control-arrow-container" onMousedown={this.handleMouseDownOnArrow}>
<ArrowIcon class={arrowClass} />
{ this.getArrow() }
</div>
)
},
Expand Down
25 changes: 20 additions & 5 deletions src/components/Option.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@
)
},

getArrow() {
const { instance } = this
const arrowIconRenderer = instance.$scopedSlots['arrow-icon']

const arrowClass = {
'vue-treeselect__option-arrow': true,
'vue-treeselect__option-arrow--rotated': this.shouldExpand,
'vue-treeselect__option-arrow--custom': arrowIconRenderer,
}

if (arrowIconRenderer) {
return (
<div class={arrowClass}> { arrowIconRenderer() }</div>
)
}

return <ArrowIcon class={arrowClass} />
},

renderArrow() {
const { instance, node } = this

Expand All @@ -81,15 +100,11 @@
appear: true,
},
}
const arrowClass = {
'vue-treeselect__option-arrow': true,
'vue-treeselect__option-arrow--rotated': this.shouldExpand,
}

return (
<div class="vue-treeselect__option-arrow-container" onMousedown={this.handleMouseDownOnArrow}>
<transition {...transitionProps}>
<ArrowIcon class={arrowClass} />
{ this.getArrow() }
</transition>
</div>
)
Expand Down