Skip to content

Commit

Permalink
Merge branch 'main' into 2795-navbar-dropdown-item-transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
ElishaSamPeterPrabhu authored Jan 6, 2025
2 parents 131e611 + c5fe88c commit e12596d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions stencil-workspace/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ export namespace Components {
* A promise that returns the filtered options.
*/
"filterOptions": (search: string) => Promise<ModusAutocompleteOption[] | string[]>;
/**
* Focus the autocomplete component
*/
"focusInput": () => Promise<void>;
/**
* Whether the search icon is included.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Listen,
Element,
Watch,
Method,
} from '@stencil/core';

import { IconSearch } from '../../icons/svgs/icon-search';
Expand Down Expand Up @@ -159,6 +160,16 @@ export class ModusAutocomplete {
}
}

/** Focus the autocomplete component */
@Method()
async focusInput(): Promise<void> {
const textInputElement = this.el.shadowRoot.querySelector('modus-text-input');

if (textInputElement) {
textInputElement.focusInput();
}
}

@Listen('mousedown', { target: 'document' })
onMouseDown(event: MouseEvent): void {
if (!this.hasFocus) {
Expand Down
13 changes: 13 additions & 0 deletions stencil-workspace/src/components/modus-autocomplete/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
| `valueChange` | An event that fires when the input value changes. Emits the value string. | `CustomEvent<string \| string[]>` |


## Methods

### `focusInput() => Promise<void>`

Focus the autocomplete component

#### Returns

Type: `Promise<void>`




## Dependencies

### Used by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,23 @@ export class ModusTableCellEditor {
selectedOption = this.editedValue as string;
}

function handleArrowKeys(e: KeyboardEvent, callback: (e: KeyboardEvent) => void) {
const code = e.key.toLowerCase();
if (code === KEYBOARD_UP || code === KEYBOARD_DOWN) {
e.stopPropagation();
} else callback(e);
}

return (
<div class="autocomplete-container">
<modus-autocomplete
{...this.getDefaultProps('Autocomplete input')}
include-search-icon="false"
size="medium"
ref={(el) => (this.inputElement = el)}
options={options}
onBlur={this.handleBlur}
onKeyDown={(e) => e.stopPropagation()}
onKeyDown={(e) => handleArrowKeys(e, this.handleKeyDown)}
filterOptions={
args.filterOptions
? (...props) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,9 @@ interface ModusAutocompleteOption {
| `optionSelected` | An event that fires when a dropdown option is selected. Emits the option id. | `CustomEvent<string>` |
| `valueChange` | An event that fires when the input value changes. Emits the value string. | `CustomEvent<string \|string[]>` |
| `selectionsChanged` | An event that fires when an option is selected/removed. Emits the option ids. | `CustomEvent<string[]>` |
### Methods
| Method name | Description | Parameter | Return |
| ------------ | --------------- | --------- | --------------- |
| `focusInput` | Focus the input | | `Promise<void>` |

0 comments on commit e12596d

Please sign in to comment.