Skip to content

Commit

Permalink
feat(NcRichContenteditable): programmatically show tributes
Browse files Browse the repository at this point in the history
Signed-off-by: DorraJaouad <[email protected]>
  • Loading branch information
DorraJaouad committed Jun 10, 2024
1 parent 6e81022 commit a68df49
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/components/NcRichContenteditable/NcRichContenteditable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,48 @@ export default {
</style>
```

### Using public methods

```vue
<template>
<div>
<div class="buttons-wrapper">
<NcButton class="show-slash-button" @click="showSlashCommands">Slash commands</NcButton>
<NcButton class="focus-button" @click="focus">Focus on input</NcButton>
</div>
<NcRichContenteditable
ref="contenteditable"
v-model="message"
label="Write a comment"
:maxlength="100"/>
</div>
</template>
<script>
export default {
data() {
return {
message: '**Lorem ipsum** dolor sit amet. ',
}
},
methods: {
showSlashCommands() {
this.$refs.contenteditable.showTribute('/')
},
focus() {
this.$refs.contenteditable.focus()
},
},
}
</script>
<style lang="scss" scoped>
.buttons-wrapper {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
</style>
```

</docs>

<template>
Expand Down Expand Up @@ -911,6 +953,8 @@ export default {
this.getTributeContainer().setAttribute('class', this.tribute.current.collection.containerClass || this.$style['tribute-container'])
this.setupTributeIntegration()
// Remove the event handler if any
document.removeEventListener('click', this.hideTribute, true)
} else {
// Cancel loading data for autocomplete
// Otherwise it could be received when another autocomplete is already opened
Expand Down Expand Up @@ -990,6 +1034,28 @@ export default {
this.getTributeContainer().classList.remove(this.$style['tribute-container--focus-visible'])
}
},
/**
* Show tribute menu programmatically.
* @param {string} trigger - trigger character, can be '/', '@', or ':'
*
* @public
*/
showTribute(trigger) {
this.focus()
const index = this.tribute.collection.findIndex(collection => collection.trigger === trigger)
this.tribute.showMenuForCollection(this.$refs.contenteditable, index)
document.addEventListener('click', this.hideTribute, true)
},
/**
* Hide tribute menu programmatically
*
*/
hideTribute() {
this.tribute.hideMenu()
document.removeEventListener('click', this.hideTribute, true)
},
},
}
</script>
Expand Down

0 comments on commit a68df49

Please sign in to comment.