Skip to content

Commit

Permalink
docs(text-editor): update examples with new event
Browse files Browse the repository at this point in the history
Use the new interaction event in `limel-list` to better handle user
interaction.

Previously there was a bug when a user clicked on the same element that
was previously selected with keyboard navigation.
  • Loading branch information
civing committed Dec 4, 2024
1 parent f97c850 commit 681addb
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/components/text-editor/examples/text-editor-custom-triggers.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Button,
LimelListCustomEvent,
ListItem,
LimelMenuListCustomEvent,
MenuItem,
} from '@limetech/lime-elements';
import { Component, h, State, Element, Watch } from '@stencil/core';
import {
Expand Down Expand Up @@ -52,7 +52,7 @@ export class TextEditorCustomTriggersExample {
private insertMode: 'text' | 'chip' = 'text';

@State()
private items: Array<ListItem<number>> = [
private items: Array<MenuItem<number>> = [
{ text: 'Wolverine', value: 1, icon: 'wolf', selected: true },
{ text: 'Captain America', value: 2, icon: 'captain_america' },
{ text: 'Superman', value: 3, icon: 'superman' },
Expand All @@ -61,7 +61,7 @@ export class TextEditorCustomTriggersExample {
];

@State()
private visibleItems: Array<ListItem<number>>;
private visibleItems: Array<MenuItem<number>>;

@Element()
private host: HTMLLimelPopoverElement;
Expand All @@ -88,7 +88,7 @@ export class TextEditorCustomTriggersExample {
@Watch('inputText')
protected watchInputText() {
if (this.isPickerOpen) {
this.visibleItems = this.items.filter((item: ListItem<number>) =>
this.visibleItems = this.items.filter((item: MenuItem<number>) =>
item.text.toLowerCase().includes(this.inputText),
);
}
Expand Down Expand Up @@ -122,7 +122,7 @@ export class TextEditorCustomTriggersExample {
}

if (event.key === ENTER || event.key === TAB) {
const selectedItem: ListItem | undefined = this.visibleItems.find(
const selectedItem: MenuItem | undefined = this.visibleItems.find(
(item) => item.selected,
);

Expand Down Expand Up @@ -227,7 +227,7 @@ export class TextEditorCustomTriggersExample {
);
};

private renderList = (items: Array<ListItem<number>>) => {
private renderList = (items: Array<MenuItem<number>>) => {
if (items.length === 0) {
return (
<div style={{ padding: '0.5rem' }}>
Expand All @@ -237,10 +237,9 @@ export class TextEditorCustomTriggersExample {
}

return (
<limel-list
<limel-menu-list
items={items}
onChange={this.handleListChange}
type="selectable"
onInteract={this.handleListInteraction}
/>
);
};
Expand All @@ -265,19 +264,17 @@ export class TextEditorCustomTriggersExample {
this.value = event.detail;
};

private handleListChange = (
event: LimelListCustomEvent<ListItem<number>>,
private handleListInteraction = (
event: LimelMenuListCustomEvent<MenuItem<number>>,
) => {
if (event.detail.selected) {
this.insertItem(event.detail);
}
this.insertItem(event.detail);
};

private handleInsertModeChange = (event: CustomEvent<Button>) => {
this.insertMode = event.detail.title as any;
};

private insertItem = (item: ListItem) => {
private insertItem = (item: MenuItem) => {
this.removeAllSelections();
this.visibleItems = this.items;
if (this.insertMode === 'text') {
Expand Down

0 comments on commit 681addb

Please sign in to comment.