Skip to content

Commit

Permalink
Add text input and fix styles to filter options
Browse files Browse the repository at this point in the history
  • Loading branch information
selinali2010 committed Feb 22, 2023
1 parent 73e2c2d commit 0f139db
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/renderer/AutoEQ.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const AutoEQ = () => {
handleChange={handleDeviceChange}
isDisabled={!!globalError}
noSelectionPlaceholder={NO_DEVICE_SELECTION}
isFilterable
/>
Target Frequency Response:
<Dropdown
Expand Down
1 change: 1 addition & 0 deletions src/renderer/PresetsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ const PresetsBar = () => {
value={presetName}
handleChange={handleChangeSelectedPreset}
isDisabled={!!globalError}
emptyOptionsPlaceholder="No presets found."
/>
<Button
ariaLabel="Load selected preset"
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/styles/AutoEQ.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ $auto-eq-dropdown-width: 220px;
width: $auto-eq-dropdown-width;
}

// Add padding around the text input for filtering the drop down
.starting-item {
padding: $spacing-xs;
}

.list {
// Assign fixed width to dropdown menu
width: $auto-eq-dropdown-width + $spacing-s;
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/styles/Dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
}
}

// Clip content in the selected entry that exceeds the container
div:first-child {
text-overflow: ellipsis;
white-space: nowrap;
overflow-x: clip;
}

svg {
width: 36px;
height: auto;
Expand All @@ -55,12 +62,12 @@
}
}

.list {
.list-wrapper {
// Position the drop down menu
position: absolute;
margin-block-start: -4px;

z-index: 1;
z-index: 2;

svg {
width: 36px;
Expand Down
47 changes: 25 additions & 22 deletions src/renderer/styles/List.scss
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
@import 'color';
@import 'spacing';

.list {
// Remove default styles
list-style-type: none;
padding-inline-start: 0px;
margin-block-start: 0px;
margin-block-end: 0px;

// Apply custom styles
.list-wrapper {
// Apply custom styles for the list wrapper
background: $primary-dark;
color: $white;
border: solid $spacing-xxs $secondary-default;
border-radius: 4px;
text-align: start;

overflow-y: auto;
.list {
// Remove default styles of the ul element
list-style-type: none;
padding-inline-start: 0px;
margin-block-start: 0px;
margin-block-end: 0px;

li {
cursor: pointer;
padding: $spacing-xs;
align-content: center;
font-size: small;
// Apply custom styles
overflow-y: auto;

&.selected {
background: $primary-light;
}
li {
cursor: pointer;
padding: $spacing-xs;
align-content: center;
font-size: small;

&.selected {
background: $primary-light;
}

&:focus,
&:focus-visible,
&:focus-within {
background: $secondary-dark;
outline: none;
&:focus,
&:focus-visible,
&:focus-within {
background: $secondary-dark;
outline: none;
}
}
}
}
28 changes: 26 additions & 2 deletions src/renderer/widgets/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ArrowIcon from '../icons/ArrowIcon';
import '../styles/Dropdown.scss';
import { useClickOutside, useFocusOutside } from '../utils/utils';
import List from './List';
import TextInput from './TextInput';

interface IOptionEntry {
value: string;
Expand All @@ -24,6 +25,7 @@ interface IDropdownProps {
isDisabled: boolean;
noSelectionPlaceholder?: JSX.Element | string;
emptyOptionsPlaceholder?: JSX.Element | string;
isFilterable?: boolean;
handleChange: (newValue: string) => void;
}

Expand All @@ -35,11 +37,22 @@ const Dropdown = ({
noSelectionPlaceholder,
emptyOptionsPlaceholder,
handleChange,
isFilterable = false,
}: IDropdownProps) => {
const nullElement = createElement('div');
const [isOpen, setIsOpen] = useState<boolean>(false);
const dropdownRef = useRef<HTMLDivElement>(null);

const [searchString, setSearchString] = useState<string>('');

const filteredOptions = useMemo(
() =>
options.filter((o) =>
o.value.toLowerCase().startsWith(searchString.toLowerCase())
),
[options, searchString]
);

useEffect(() => {
if (isDisabled) {
setIsOpen(false);
Expand Down Expand Up @@ -107,10 +120,21 @@ const Dropdown = ({
<List
name={name}
value={value}
options={options}
options={filteredOptions}
isDisabled={isDisabled}
handleChange={onChange}
focusOnRender
focusOnRender={!isFilterable}
startingItem={
isFilterable ? (
<TextInput
value={searchString}
ariaLabel="Filter audio devices"
isDisabled={isDisabled}
errorMessage=""
handleChange={(newValue) => setSearchString(newValue)}
/>
) : undefined
}
/>
)}
</div>
Expand Down
54 changes: 37 additions & 17 deletions src/renderer/widgets/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface IListProps {
className?: string;
itemClassName?: string;
focusOnRender?: boolean;
startingItem?: JSX.Element;
emptyOptionsPlaceholder?: JSX.Element | string;
}

const List = ({
Expand All @@ -34,6 +36,8 @@ const List = ({
className,
itemClassName,
focusOnRender = false,
startingItem,
emptyOptionsPlaceholder = 'No options found.',
}: IListProps) => {
const inputRefs = useMemo(
() =>
Expand Down Expand Up @@ -91,28 +95,44 @@ const List = ({
);

return (
<ul className={`list ${className || ''}`} aria-label={`${name}-items`}>
{options.map((entry: IOptionEntry, index: number) => {
return (
<div className={`list-wrapper ${className || ''}`}>
{startingItem && (
<div role="menuitem" className="row starting-item">
{startingItem}
</div>
)}
<ul className={`list ${className || ''}`} aria-label={`${name}-items`}>
{options.map((entry: IOptionEntry, index: number) => {
return (
<li
role="menuitem"
ref={inputRefs[index]}
className={`row ${itemClassName || ''} ${
entry.value === value ? 'selected' : ''
}`}
key={entry.value}
value={entry.value}
aria-label={entry.label}
onClick={onClick(entry.value)}
onKeyDown={handleItemKeyPress(entry, index)}
onMouseEnter={onMouseEnter(index)}
tabIndex={0}
>
{entry.display}
</li>
);
})}
{options.length === 0 && (
<li
role="menuitem"
ref={inputRefs[index]}
className={`row ${itemClassName || ''} ${
entry.value === value ? 'selected' : ''
}`}
key={entry.value}
value={entry.value}
aria-label={entry.label}
onClick={onClick(entry.value)}
onKeyDown={handleItemKeyPress(entry, index)}
onMouseEnter={onMouseEnter(index)}
className={`row ${itemClassName || ''} `}
tabIndex={0}
>
{entry.display}
{emptyOptionsPlaceholder}
</li>
);
})}
</ul>
)}
</ul>
</div>
);
};

Expand Down

0 comments on commit 0f139db

Please sign in to comment.