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 224004b commit 93f0b0c
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/components/NcRichContenteditable/NcRichContenteditable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Try mentioning user @Test01 or inserting emoji :smile
```vue
<template>
<div>
<NcButton class="show-slash-button" @click.stop="showSlashCommands('/')">Slash commands</NcButton>
<NcRichContenteditable
ref="contenteditable"
label="Write a comment"
:value.sync="message"
:auto-complete="autoComplete"
Expand Down Expand Up @@ -194,7 +196,10 @@ export default {
},
onSubmit() {
alert(this.message)
}
},
showSlashCommands(trigger) {
this.$refs.contenteditable.showTribute(trigger)
},
}
}
</script>
Expand Down Expand Up @@ -922,6 +927,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)
} else {
// Cancel loading data for autocomplete
// Otherwise it could be received when another autocomplete is already opened
Expand Down Expand Up @@ -1001,6 +1008,28 @@ export default {
this.getTributeContainer().classList.remove(this.$style['tribute-container--focus-visible'])
}
},
/**
* show tribute menu programmatically
* @param {string} trigger - trigger character
*
* @public
*/
showTribute(trigger) {
this.$refs.contenteditable.focus()
const index = this.tribute.collection.findIndex(collection => collection.trigger === trigger)
this.tribute.showMenuForCollection(this.$refs.contenteditable, index)
document.addEventListener('click', this.hideTribute)
},
/**
* Hide tribute menu programmatically
*
*/
hideTribute() {
this.tribute.hideMenu()
document.removeEventListener('click', this.hideTribute)
},
},
}
</script>
Expand Down

0 comments on commit 93f0b0c

Please sign in to comment.