Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GEN-2084]: enhance AutocompleteInput with autoFocus #2044

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const ActionModal: React.FC<Props> = ({ isOpen, onClose }) => {
>
<ModalBody>
<SectionTitle title='Select Action' description='Select an action to modify telemetry data before it`s sent to destinations. Choose an action type and configure its details.' />
<AutocompleteInput options={ACTION_OPTIONS} selectedOption={selectedItem} onOptionSelect={handleSelect} style={{ marginTop: '24px' }} />
<AutocompleteInput options={ACTION_OPTIONS} selectedOption={selectedItem} onOptionSelect={handleSelect} style={{ marginTop: '24px' }} autoFocus />

{!!selectedItem?.type ? (
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, type ChangeEvent, type KeyboardEvent, type FC } from 'react';
import React, { useState, type ChangeEvent, type KeyboardEvent, type FC, type InputHTMLAttributes } from 'react';
import { SVG } from '@/assets';
import { Text } from '../text';
import styled from 'styled-components';
Expand All @@ -11,7 +11,7 @@ export interface Option {
items?: Option[]; // For handling a list of items
}

interface Props {
interface Props extends InputHTMLAttributes<HTMLInputElement> {
options: Option[];
placeholder?: string;
selectedOption?: Option;
Expand All @@ -34,7 +34,7 @@ const filterOptions = (optionsList: Option[], input: string): Option[] => {
}, []);
};

export const AutocompleteInput: FC<Props> = ({ placeholder = 'Type to search...', options, selectedOption, onOptionSelect, style, disabled }) => {
export const AutocompleteInput: FC<Props> = ({ placeholder = 'Type to search...', options, selectedOption, onOptionSelect, style, disabled, ...props }) => {
const [query, setQuery] = useState(selectedOption?.label || '');
const [filteredOptions, setFilteredOptions] = useState<Option[]>(filterOptions(options, ''));
const [showOptions, setShowOptions] = useState(false);
Expand Down Expand Up @@ -99,6 +99,7 @@ export const AutocompleteInput: FC<Props> = ({ placeholder = 'Type to search...'
disabled={disabled}
onBlur={() => !disabled && setShowOptions(false)}
onFocus={() => !disabled && setShowOptions(true)}
{...props}
/>
</InputWrapper>

Expand Down Expand Up @@ -199,10 +200,10 @@ const StyledInput = styled.input`

const OptionsList = styled.ul`
position: absolute;
max-height: 348px;
max-height: 500px;
top: 32px;
border-radius: 24px;
width: calc(100% - 24px);
width: calc(100% - 32px);
overflow-y: auto;
background-color: ${({ theme }) => theme.colors.dropdown_bg};
border: 1px solid ${({ theme }) => theme.colors.border};
Expand Down
Loading