Skip to content

Commit

Permalink
fix: icon picker keyboard interactions (#1666)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meierschlumpf authored Dec 15, 2024
1 parent 8ca0016 commit 82ec77d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[data-combobox-selected="true"] .iconCard {
border-color: var(--mantine-primary-color-6);
}
64 changes: 37 additions & 27 deletions apps/nextjs/src/components/icons/picker/icon-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { useDebouncedValue } from "@mantine/hooks";
import { clientApi } from "@homarr/api/client";
import { useScopedI18n } from "@homarr/translation/client";

import classes from "./icon-picker.module.css";

interface IconPickerProps {
initialValue?: string;
onChange: (iconUrl: string) => void;
Expand Down Expand Up @@ -49,35 +51,43 @@ export const IconPicker = ({ initialValue, onChange, error, onFocus, onBlur }: I
const totalOptions = data?.icons.reduce((acc, group) => acc + group.icons.length, 0) ?? 0;
const groups = data?.icons.map((group) => {
const options = group.icons.map((item) => (
<UnstyledButton
onClick={() => {
const value = item.url;
startTransition(() => {
setValue(value);
setPreviewUrl(value);
setSearch(value);
onChange(value);
combobox.closeDropdown();
});
}}
<Combobox.Option
key={item.id}
value={item.url}
p={0}
h="calc(2*var(--mantine-spacing-sm)+25px)"
w="calc(2*var(--mantine-spacing-sm)+25px)"
>
<Indicator label="SVG" disabled={!item.url.endsWith(".svg")} size={16}>
<Card
p="sm"
pos="relative"
style={{
overflow: "visible",
cursor: "pointer",
}}
withBorder
>
<Box w={25} h={25}>
<Image src={item.url} w={25} h={25} radius="md" />
</Box>
</Card>
</Indicator>
</UnstyledButton>
<UnstyledButton
onClick={() => {
const value = item.url;
startTransition(() => {
setValue(value);
setPreviewUrl(value);
setSearch(value);
onChange(value);
combobox.closeDropdown();
});
}}
>
<Indicator label="SVG" disabled={!item.url.endsWith(".svg")} size={16}>
<Card
p="sm"
pos="relative"
style={{
overflow: "visible",
cursor: "pointer",
}}
className={classes.iconCard}
withBorder
>
<Box w={25} h={25}>
<Image src={item.url} w={25} h={25} radius="md" />
</Box>
</Card>
</Indicator>
</UnstyledButton>
</Combobox.Option>
));

return (
Expand Down

0 comments on commit 82ec77d

Please sign in to comment.