Skip to content
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
5 changes: 5 additions & 0 deletions docs/examples/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export default () => (
value: 'bamboo',
label: 'Bamboo',
},
{
value: 'dark',
label: 'Dark',
disabled: true,
},
{
value: 'cat',
label: 'Cat',
Expand Down
5 changes: 4 additions & 1 deletion src/Mentions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ const InternalMentions = forwardRef<MentionsRef, MentionsProps>(
};

const selectOption = (option: OptionProps) => {
const { value: mentionValue = '' } = option;
const { value: mentionValue = '', disabled } = option;
if (disabled) {
return;
}
Comment on lines +300 to +303

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change correctly prevents the selection of a disabled option.

For an improved user experience, you might also consider preventing keyboard navigation to disabled options. Currently, a user can still highlight a disabled option using the arrow keys, and when they press Enter, nothing happens, which could be confusing.

A potential enhancement would be to update the onInternalKeyDown handler to skip over disabled options when navigating with the UP or DOWN arrow keys. While this is outside the scope of the current changes, it's a related improvement that would make the component more intuitive.

const { text, selectionLocation } = replaceWithMeasure(mergedValue, {
measureLocation: mergedMeasureLocation,
targetText: mentionValue,
Expand Down