Skip to content

Commit

Permalink
Fix asset selector onchange event (#1868)
Browse files Browse the repository at this point in the history
* Fix asset selector onchange event

* restore keyboard navigation
  • Loading branch information
grod220 authored Oct 22, 2024
1 parent 45aceab commit 74b53af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-ducks-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@penumbra-zone/ui': patch
---

Fix asset selector not firing onChange event
27 changes: 12 additions & 15 deletions packages/ui/src/Dialog/RadioItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeyboardEventHandler, MouseEventHandler, ReactNode, useMemo } from 'react';
import React, { ReactNode, useMemo } from 'react';
import { RadioGroupItem } from '@radix-ui/react-radio-group';
import { styled } from 'styled-components';
import { motion } from 'framer-motion';
Expand Down Expand Up @@ -97,22 +97,20 @@ export const RadioItem = ({
onClose,
onSelect,
}: DialogRadioItemProps) => {
const onEnter: KeyboardEventHandler<HTMLButtonElement> = event => {
if (event.key === 'Enter') {
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
// Is a click and not an arrow key up/down
if (event.detail > 0) {
onSelect?.();
onClose?.();
}
};

const onMouseDown: MouseEventHandler<HTMLButtonElement> = () => {
// close only after the value is selected by onClick
setTimeout(() => {
const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
onSelect?.();
onClose?.();
}, 0);
};

// click is triggered by radix-ui on focus, click, arrow selection, etc. – basically always
const onClick = () => {
onSelect?.();
}
};

const descriptionText = useMemo(() => {
Expand All @@ -135,9 +133,8 @@ export const RadioItem = ({
<RadioGroupItem key={value} disabled={disabled} value={value} asChild>
<Root
{...asTransientProps({ actionType, disabled })}
onKeyDown={onEnter}
onMouseDown={onMouseDown}
onClick={onClick}
onClick={handleClick}
onKeyDown={handleKeyDown}
>
<Info>
{startAdornment}
Expand Down

0 comments on commit 74b53af

Please sign in to comment.