| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Activates a suggestion menu to expand text snippets as you type.
$ npm install --save @github/text-expander-element
Import as ES modules:
import '@github/text-expander-element'With a script tag:
<script type="module" src="./node_modules/@github/text-expander-element/dist/bundle.js"><text-expander keys=": @ #" multiword="#">
<textarea></textarea>
</text-expander>text-expander-change is fired when a key is matched. In event.detail you can find:
const expander = document.querySelector('text-expander')
expander.addEventListener('text-expander-change', function(event) {
const {key, provide, text} = event.detail
if (key !== ':') return
const suggestions = document.querySelector('.emoji-suggestions').cloneNode(true)
suggestions.hidden = false
for (const suggestion of suggestions.children) {
if (!suggestion.textContent.match(text)) {
suggestion.remove()
}
}
provide(Promise.resolve({matched: suggestions.childElementCount > 0, fragment: suggestions}))
})The returned fragment should be consisted of filtered [role=option] items to be selected. For example:
<ul class="emoji-suggestions" hidden>
<li role="option" data-value="🐈">🐈 :cat2:</li>
<li role="option" data-value="🐕">🐕 :dog:</li>
</ul>text-expander-value is fired when an item is selected. In event.detail you can find:
const expander = document.querySelector('text-expander')
expander.addEventListener('text-expander-value', function(event) {
const {key, item} = event.detail
if (key === ':') {
event.detail.value = item.getAttribute('data-value')
}
})text-expander-committed is fired after the underlying input value has been updated in the DOM. In event.detail you can find:
const expander = document.querySelector('text-expander')
expander.addEventListener('text-expander-committed', function(event) {
const {input} = event.detail
})text-expander-activate is fired just after the menu has been assigned and appended to the DOM, and just before it is about to be positioned near the text to expand. This is useful for assigning classes or calling imperative methods to show the menu, such as .showPopover().
text-expander-deactivate is fired just before the menu is going to be unassigned and removed from the DOM. This is useful for removing classes or running cleanup like removing from caches.
Browsers without native custom element support require a polyfill.
npm install npm test
Distributed under the MIT license. See LICENSE for details.
| Back | FazBrowse Home | New Git URL |