Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lerte committed Nov 12, 2024
1 parent e0cab5c commit 65de8d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 8 additions & 4 deletions packages/actify/src/components/Label/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
'use client'

import { LabelAriaProps } from 'react-aria'
import React from 'react'

interface LabelProps extends React.ComponentProps<'label'> {}
const Label = ({ ref, children, ...rest }: LabelProps) => {
interface LabelProps extends LabelAriaProps, React.ComponentProps<'label'> {
children?: React.ReactNode
}

const Label = ({ ref, children, ...props }: LabelProps) => {
return (
<label
ref={ref}
{...rest}
{...props}
onMouseDown={(event) => {
// only prevent text selection if clicking inside the label itself
const target = event.target as HTMLElement
if (target.closest('button, input, select, textarea')) return

rest.onMouseDown?.(event)
props.onMouseDown?.(event)
// prevent text selection when double clicking label
if (!event.defaultPrevented && event.detail > 1) event.preventDefault()
}}
Expand Down
9 changes: 7 additions & 2 deletions packages/actify/src/components/Radio/RadioGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { AriaRadioGroupProps, useRadioGroup } from 'react-aria'
import { RadioGroupState, useRadioGroupState } from 'react-stately'

import { Label } from '../Label'
import React from 'react'

export const RadioContext = React.createContext<RadioGroupState | {}>({})

type RadioGroupProps = {} & AriaRadioGroupProps & React.ComponentProps<'div'>
interface RadioGroupProps extends AriaRadioGroupProps {
style?: React.CSSProperties
className?: string
children?: React.ReactNode
}

const RadioGroup = (props: RadioGroupProps) => {
const { style, className, children, label, description, errorMessage } = props
Expand All @@ -15,7 +20,7 @@ const RadioGroup = (props: RadioGroupProps) => {

return (
<div {...radioGroupProps} style={style} className={className}>
<span {...labelProps}>{label}</span>
{label && <Label {...labelProps}>{label}</Label>}
<RadioContext value={state}>{children}</RadioContext>
{description && (
<div {...descriptionProps} style={{ fontSize: 12 }}>
Expand Down

0 comments on commit 65de8d5

Please sign in to comment.