Skip to content
Merged
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
17 changes: 14 additions & 3 deletions packages/flourish-ui/src/components/Autocomplete/Autocomplete.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import '../../index.scss';

$autocomplete_width: 200px;
$autocomplete_width: 250px;

.#{$prefix}autocomplete-trigger-container {
display: flex;
Expand All @@ -13,13 +13,25 @@ $autocomplete_width: 200px;
sans-serif;
}

.#{$prefix}searchbar {
position: relative;
display: flex;
align-items: center;
}

.#{$prefix}searchbar-clear-btn {
position: absolute;
right: 0;
}

.react-aria-ComboBox {
max-width: max-content;
}

.react-aria-Input {
width: $autocomplete_width;
padding: 5px calc($f-spacing-4 * 1px);
padding: calc($f-spacing-5 * 1px);
padding-right: 32px;
background-color: $f-color-bg-light;
border: 2px solid $f-color-primary-light;
border-radius: calc($f-border-soft-corner * 1px);
Expand All @@ -41,7 +53,6 @@ $autocomplete_width: 200px;
.react-aria-ListBox {
width: $autocomplete_width;
z-index: 1000;
width: 200px;
max-height: 150px;
background-color: $f-color-bg-light;
border: 2px solid $f-color-primary-light;
Expand Down
39 changes: 35 additions & 4 deletions packages/flourish-ui/src/components/Autocomplete/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useRef, useState } from 'react'
import {
ComboBox,
ComboBoxProps,
Expand All @@ -10,6 +10,7 @@ import {
Popover
} from 'react-aria-components'
import { Testable } from '../../common-props'
import { Button } from '../Button'
import './Autocomplete.scss'

export interface AutocompleteProps<T extends object>
Expand Down Expand Up @@ -39,11 +40,41 @@ export const Autocomplete = <T extends object>({
'data-testId': testId,
...props
}: AutocompleteProps<T>) => {
const inputRef = useRef<HTMLInputElement>(null)
const [inputValue, setInputValue] = useState('')

const onDelete = (e: React.MouseEvent<Element, MouseEvent>) => {
setInputValue('')
inputRef.current?.focus()
}

return (
<ComboBox {...props} data-testId={testId}>
<ComboBox
{...props}
data-testId={testId}
inputValue={inputValue}
onInputChange={setInputValue}
>
<div className="f-autocomplete-trigger-container">
{isLabelVisible && <Label className="f-autocomplete-label">{label}</Label>}
<Input data-testId={`${testId}-trigger`} aria-label={label} />
{isLabelVisible && (
<Label className="f-autocomplete-label">{label}</Label>
)}
<div className="f-searchbar">
<Input
ref={inputRef}
data-testId={`${testId}-trigger`}
aria-label={label}
/>
{inputValue.length > 0 && (
<Button
className="f-searchbar-clear-btn"
label="Clear search..."
variant="icon"
icon="close"
onClick={onDelete}
/>
)}
</div>
</div>
<Popover>
<ListBox>{children}</ListBox>
Expand Down