Socket
Socket
Sign inDemoInstall

@radix-ui/react-radio-group

Package Overview
Dependencies
Maintainers
6
Versions
207
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-radio-group - npm Package Compare versions

Comparing version 1.1.4-rc.11 to 1.2.0-rc.1

65

dist/index.d.ts

@@ -1,7 +0,19 @@

import * as React from "react";
import * as Radix from "@radix-ui/react-primitive";
import { Primitive } from "@radix-ui/react-primitive";
import * as RovingFocusGroup from "@radix-ui/react-roving-focus";
type PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;
interface RadioProps extends PrimitiveButtonProps {
import * as React from 'react';
import * as Radix from '@radix-ui/react-primitive';
import { Primitive } from '@radix-ui/react-primitive';
import * as RovingFocusGroup from '@radix-ui/react-roving-focus';
declare type Scope<C = any> = {
[scopeName: string]: React.Context<C>[];
} | undefined;
declare type ScopeHook = (scope: Scope) => {
[__scopeProp: string]: Scope;
};
interface CreateScope {
scopeName: string;
(): ScopeHook;
}
declare type PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;
interface RadioProps$1 extends PrimitiveButtonProps {
checked?: boolean;

@@ -11,5 +23,5 @@ required?: boolean;

}
declare const Radio: React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLButtonElement>>;
type PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;
interface RadioIndicatorProps extends PrimitiveSpanProps {
declare const Radio: React.ForwardRefExoticComponent<RadioProps$1 & React.RefAttributes<HTMLButtonElement>>;
declare type PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;
interface RadioIndicatorProps$1 extends PrimitiveSpanProps {
/**

@@ -21,5 +33,6 @@ * Used to force mounting when more control is needed. Useful when

}
declare const RadioIndicator: React.ForwardRefExoticComponent<RadioIndicatorProps & React.RefAttributes<HTMLSpanElement>>;
export const createRadioGroupScope: import("@radix-ui/react-context").CreateScope;
type RadioGroupContextValue = {
declare const RadioIndicator: React.ForwardRefExoticComponent<RadioIndicatorProps$1 & React.RefAttributes<HTMLSpanElement>>;
declare const createRadioGroupScope: CreateScope;
declare type RadioGroupContextValue = {
name?: string;

@@ -31,5 +44,5 @@ required: boolean;

};
type RovingFocusGroupProps = Radix.ComponentPropsWithoutRef<typeof RovingFocusGroup.Root>;
type PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;
export interface RadioGroupProps extends PrimitiveDivProps {
declare type RovingFocusGroupProps = Radix.ComponentPropsWithoutRef<typeof RovingFocusGroup.Root>;
declare type PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;
interface RadioGroupProps extends PrimitiveDivProps {
name?: RadioGroupContextValue['name'];

@@ -45,16 +58,16 @@ required?: Radix.ComponentPropsWithoutRef<typeof Radio>['required'];

}
export const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
type _RadioProps1 = Radix.ComponentPropsWithoutRef<typeof Radio>;
export interface RadioGroupItemProps extends Omit<_RadioProps1, 'onCheck' | 'name'> {
declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
declare type RadioProps = Radix.ComponentPropsWithoutRef<typeof Radio>;
interface RadioGroupItemProps extends Omit<RadioProps, 'onCheck' | 'name'> {
value: string;
}
export const RadioGroupItem: React.ForwardRefExoticComponent<RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>>;
type _RadioIndicatorProps1 = Radix.ComponentPropsWithoutRef<typeof RadioIndicator>;
export interface RadioGroupIndicatorProps extends _RadioIndicatorProps1 {
declare const RadioGroupItem: React.ForwardRefExoticComponent<RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>>;
declare type RadioIndicatorProps = Radix.ComponentPropsWithoutRef<typeof RadioIndicator>;
interface RadioGroupIndicatorProps extends RadioIndicatorProps {
}
export const RadioGroupIndicator: React.ForwardRefExoticComponent<RadioGroupIndicatorProps & React.RefAttributes<HTMLSpanElement>>;
export const Root: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
export const Item: React.ForwardRefExoticComponent<RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>>;
export const Indicator: React.ForwardRefExoticComponent<RadioGroupIndicatorProps & React.RefAttributes<HTMLSpanElement>>;
declare const RadioGroupIndicator: React.ForwardRefExoticComponent<RadioGroupIndicatorProps & React.RefAttributes<HTMLSpanElement>>;
declare const Root: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
declare const Item: React.ForwardRefExoticComponent<RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>>;
declare const Indicator: React.ForwardRefExoticComponent<RadioGroupIndicatorProps & React.RefAttributes<HTMLSpanElement>>;
//# sourceMappingURL=index.d.ts.map
export { Indicator, Item, RadioGroup, RadioGroupIndicator, type RadioGroupIndicatorProps, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps, Root, createRadioGroupScope };

565

dist/index.js

@@ -1,290 +0,307 @@

var $9yYIj$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
var $9yYIj$react = require("react");
var $9yYIj$radixuiprimitive = require("@radix-ui/primitive");
var $9yYIj$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
var $9yYIj$radixuireactcontext = require("@radix-ui/react-context");
var $9yYIj$radixuireactprimitive = require("@radix-ui/react-primitive");
var $9yYIj$radixuireactrovingfocus = require("@radix-ui/react-roving-focus");
var $9yYIj$radixuireactusecontrollablestate = require("@radix-ui/react-use-controllable-state");
var $9yYIj$radixuireactdirection = require("@radix-ui/react-direction");
var $9yYIj$radixuireactusesize = require("@radix-ui/react-use-size");
var $9yYIj$radixuireactuseprevious = require("@radix-ui/react-use-previous");
var $9yYIj$radixuireactpresence = require("@radix-ui/react-presence");
"use strict";
(() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined") return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
// packages/react/radio-group/src/RadioGroup.tsx
var React2 = __toESM(__require("react"));
var import_primitive2 = __require("@radix-ui/primitive");
var import_react_compose_refs2 = __require("@radix-ui/react-compose-refs");
var import_react_context2 = __require("@radix-ui/react-context");
var import_react_primitive2 = __require("@radix-ui/react-primitive");
var RovingFocusGroup = __toESM(__require("@radix-ui/react-roving-focus"));
var import_react_roving_focus = __require("@radix-ui/react-roving-focus");
var import_react_use_controllable_state = __require("@radix-ui/react-use-controllable-state");
var import_react_direction = __require("@radix-ui/react-direction");
$parcel$export(module.exports, "createRadioGroupScope", () => $240483839a8a76fd$export$c547093f11b76da2);
$parcel$export(module.exports, "RadioGroup", () => $240483839a8a76fd$export$a98f0dcb43a68a25);
$parcel$export(module.exports, "RadioGroupItem", () => $240483839a8a76fd$export$9f866c100ef519e4);
$parcel$export(module.exports, "RadioGroupIndicator", () => $240483839a8a76fd$export$5fb54c671a65c88);
$parcel$export(module.exports, "Root", () => $240483839a8a76fd$export$be92b6f5f03c0fe9);
$parcel$export(module.exports, "Item", () => $240483839a8a76fd$export$6d08773d2e66f8f2);
$parcel$export(module.exports, "Indicator", () => $240483839a8a76fd$export$adb584737d712b70);
/* -------------------------------------------------------------------------------------------------
* Radio
* -----------------------------------------------------------------------------------------------*/ const $ce74a64c62457efb$var$RADIO_NAME = 'Radio';
const [$ce74a64c62457efb$var$createRadioContext, $ce74a64c62457efb$export$67d2296460f1b002] = $9yYIj$radixuireactcontext.createContextScope($ce74a64c62457efb$var$RADIO_NAME);
const [$ce74a64c62457efb$var$RadioProvider, $ce74a64c62457efb$var$useRadioContext] = $ce74a64c62457efb$var$createRadioContext($ce74a64c62457efb$var$RADIO_NAME);
const $ce74a64c62457efb$export$d7b12c4107be0d61 = /*#__PURE__*/ $9yYIj$react.forwardRef((props, forwardedRef)=>{
const { __scopeRadio: __scopeRadio , name: name , checked: checked = false , required: required , disabled: disabled , value: value = 'on' , onCheck: onCheck , ...radioProps } = props;
const [button, setButton] = $9yYIj$react.useState(null);
const composedRefs = $9yYIj$radixuireactcomposerefs.useComposedRefs(forwardedRef, (node)=>setButton(node)
);
const hasConsumerStoppedPropagationRef = $9yYIj$react.useRef(false); // We set this to true by default so that events bubble to forms without JS (SSR)
const isFormControl = button ? Boolean(button.closest('form')) : true;
return /*#__PURE__*/ $9yYIj$react.createElement($ce74a64c62457efb$var$RadioProvider, {
scope: __scopeRadio,
checked: checked,
disabled: disabled
}, /*#__PURE__*/ $9yYIj$react.createElement($9yYIj$radixuireactprimitive.Primitive.button, ($parcel$interopDefault($9yYIj$babelruntimehelpersextends))({
type: "button",
role: "radio",
"aria-checked": checked,
"data-state": $ce74a64c62457efb$var$getState(checked),
"data-disabled": disabled ? '' : undefined,
disabled: disabled,
value: value
}, radioProps, {
ref: composedRefs,
onClick: $9yYIj$radixuiprimitive.composeEventHandlers(props.onClick, (event)=>{
// radios cannot be unchecked so we only communicate a checked state
if (!checked) onCheck === null || onCheck === void 0 || onCheck();
if (isFormControl) {
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(); // if radio is in a form, stop propagation from the button so that we only propagate
// one click event (from the input). We propagate changes from an input so that native
// form validation works and form events reflect radio updates.
// packages/react/radio-group/src/Radio.tsx
var React = __toESM(__require("react"));
var import_primitive = __require("@radix-ui/primitive");
var import_react_compose_refs = __require("@radix-ui/react-compose-refs");
var import_react_context = __require("@radix-ui/react-context");
var import_react_use_size = __require("@radix-ui/react-use-size");
var import_react_use_previous = __require("@radix-ui/react-use-previous");
var import_react_presence = __require("@radix-ui/react-presence");
var import_react_primitive = __require("@radix-ui/react-primitive");
var import_jsx_runtime = __require("react/jsx-runtime");
var RADIO_NAME = "Radio";
var [createRadioContext, createRadioScope] = (0, import_react_context.createContextScope)(RADIO_NAME);
var [RadioProvider, useRadioContext] = createRadioContext(RADIO_NAME);
var Radio = React.forwardRef(
(props, forwardedRef) => {
const {
__scopeRadio,
name,
checked = false,
required,
disabled,
value = "on",
onCheck,
...radioProps
} = props;
const [button, setButton] = React.useState(null);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, (node) => setButton(node));
const hasConsumerStoppedPropagationRef = React.useRef(false);
const isFormControl = button ? Boolean(button.closest("form")) : true;
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(RadioProvider, { scope: __scopeRadio, checked, disabled, children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_primitive.Primitive.button,
{
type: "button",
role: "radio",
"aria-checked": checked,
"data-state": getState(checked),
"data-disabled": disabled ? "" : void 0,
disabled,
value,
...radioProps,
ref: composedRefs,
onClick: (0, import_primitive.composeEventHandlers)(props.onClick, (event) => {
if (!checked) onCheck?.();
if (isFormControl) {
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
}
})
})), isFormControl && /*#__PURE__*/ $9yYIj$react.createElement($ce74a64c62457efb$var$BubbleInput, {
control: button,
bubbles: !hasConsumerStoppedPropagationRef.current,
name: name,
value: value,
checked: checked,
required: required,
disabled: disabled // We transform because the input is absolutely positioned but we have
,
style: {
transform: 'translateX(-100%)'
}
})
}
),
isFormControl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
BubbleInput,
{
control: button,
bubbles: !hasConsumerStoppedPropagationRef.current,
name,
value,
checked,
required,
disabled,
style: { transform: "translateX(-100%)" }
}
)
] });
}
);
Radio.displayName = RADIO_NAME;
var INDICATOR_NAME = "RadioIndicator";
var RadioIndicator = React.forwardRef(
(props, forwardedRef) => {
const { __scopeRadio, forceMount, ...indicatorProps } = props;
const context = useRadioContext(INDICATOR_NAME, __scopeRadio);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_presence.Presence, { present: forceMount || context.checked, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_primitive.Primitive.span,
{
"data-state": getState(context.checked),
"data-disabled": context.disabled ? "" : void 0,
...indicatorProps,
ref: forwardedRef
}
}));
});
/*#__PURE__*/ Object.assign($ce74a64c62457efb$export$d7b12c4107be0d61, {
displayName: $ce74a64c62457efb$var$RADIO_NAME
});
/* -------------------------------------------------------------------------------------------------
* RadioIndicator
* -----------------------------------------------------------------------------------------------*/ const $ce74a64c62457efb$var$INDICATOR_NAME = 'RadioIndicator';
const $ce74a64c62457efb$export$d35a9ffa9a04f9e7 = /*#__PURE__*/ $9yYIj$react.forwardRef((props, forwardedRef)=>{
const { __scopeRadio: __scopeRadio , forceMount: forceMount , ...indicatorProps } = props;
const context = $ce74a64c62457efb$var$useRadioContext($ce74a64c62457efb$var$INDICATOR_NAME, __scopeRadio);
return /*#__PURE__*/ $9yYIj$react.createElement($9yYIj$radixuireactpresence.Presence, {
present: forceMount || context.checked
}, /*#__PURE__*/ $9yYIj$react.createElement($9yYIj$radixuireactprimitive.Primitive.span, ($parcel$interopDefault($9yYIj$babelruntimehelpersextends))({
"data-state": $ce74a64c62457efb$var$getState(context.checked),
"data-disabled": context.disabled ? '' : undefined
}, indicatorProps, {
ref: forwardedRef
})));
});
/*#__PURE__*/ Object.assign($ce74a64c62457efb$export$d35a9ffa9a04f9e7, {
displayName: $ce74a64c62457efb$var$INDICATOR_NAME
});
/* ---------------------------------------------------------------------------------------------- */ const $ce74a64c62457efb$var$BubbleInput = (props)=>{
const { control: control , checked: checked , bubbles: bubbles = true , ...inputProps } = props;
const ref = $9yYIj$react.useRef(null);
const prevChecked = $9yYIj$radixuireactuseprevious.usePrevious(checked);
const controlSize = $9yYIj$radixuireactusesize.useSize(control); // Bubble checked change to parents (e.g form change event)
$9yYIj$react.useEffect(()=>{
const input = ref.current;
const inputProto = window.HTMLInputElement.prototype;
const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked');
const setChecked = descriptor.set;
if (prevChecked !== checked && setChecked) {
const event = new Event('click', {
bubbles: bubbles
});
setChecked.call(input, checked);
input.dispatchEvent(event);
}
}, [
prevChecked,
checked,
bubbles
]);
return /*#__PURE__*/ $9yYIj$react.createElement("input", ($parcel$interopDefault($9yYIj$babelruntimehelpersextends))({
) });
}
);
RadioIndicator.displayName = INDICATOR_NAME;
var BubbleInput = (props) => {
const { control, checked, bubbles = true, ...inputProps } = props;
const ref = React.useRef(null);
const prevChecked = (0, import_react_use_previous.usePrevious)(checked);
const controlSize = (0, import_react_use_size.useSize)(control);
React.useEffect(() => {
const input = ref.current;
const inputProto = window.HTMLInputElement.prototype;
const descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked");
const setChecked = descriptor.set;
if (prevChecked !== checked && setChecked) {
const event = new Event("click", { bubbles });
setChecked.call(input, checked);
input.dispatchEvent(event);
}
}, [prevChecked, checked, bubbles]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"input",
{
type: "radio",
"aria-hidden": true,
defaultChecked: checked
}, inputProps, {
defaultChecked: checked,
...inputProps,
tabIndex: -1,
ref: ref,
ref,
style: {
...props.style,
...controlSize,
position: 'absolute',
pointerEvents: 'none',
opacity: 0,
margin: 0
...props.style,
...controlSize,
position: "absolute",
pointerEvents: "none",
opacity: 0,
margin: 0
}
}));
};
function $ce74a64c62457efb$var$getState(checked) {
return checked ? 'checked' : 'unchecked';
}
}
);
};
function getState(checked) {
return checked ? "checked" : "unchecked";
}
const $240483839a8a76fd$var$ARROW_KEYS = [
'ArrowUp',
'ArrowDown',
'ArrowLeft',
'ArrowRight'
];
/* -------------------------------------------------------------------------------------------------
* RadioGroup
* -----------------------------------------------------------------------------------------------*/ const $240483839a8a76fd$var$RADIO_GROUP_NAME = 'RadioGroup';
const [$240483839a8a76fd$var$createRadioGroupContext, $240483839a8a76fd$export$c547093f11b76da2] = $9yYIj$radixuireactcontext.createContextScope($240483839a8a76fd$var$RADIO_GROUP_NAME, [
$9yYIj$radixuireactrovingfocus.createRovingFocusGroupScope,
$ce74a64c62457efb$export$67d2296460f1b002
]);
const $240483839a8a76fd$var$useRovingFocusGroupScope = $9yYIj$radixuireactrovingfocus.createRovingFocusGroupScope();
const $240483839a8a76fd$var$useRadioScope = $ce74a64c62457efb$export$67d2296460f1b002();
const [$240483839a8a76fd$var$RadioGroupProvider, $240483839a8a76fd$var$useRadioGroupContext] = $240483839a8a76fd$var$createRadioGroupContext($240483839a8a76fd$var$RADIO_GROUP_NAME);
const $240483839a8a76fd$export$a98f0dcb43a68a25 = /*#__PURE__*/ $9yYIj$react.forwardRef((props, forwardedRef)=>{
const { __scopeRadioGroup: __scopeRadioGroup , name: name , defaultValue: defaultValue , value: valueProp , required: required = false , disabled: disabled = false , orientation: orientation , dir: dir , loop: loop = true , onValueChange: onValueChange , ...groupProps } = props;
const rovingFocusGroupScope = $240483839a8a76fd$var$useRovingFocusGroupScope(__scopeRadioGroup);
const direction = $9yYIj$radixuireactdirection.useDirection(dir);
const [value, setValue] = $9yYIj$radixuireactusecontrollablestate.useControllableState({
// packages/react/radio-group/src/RadioGroup.tsx
var import_jsx_runtime2 = __require("react/jsx-runtime");
var ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
var RADIO_GROUP_NAME = "RadioGroup";
var [createRadioGroupContext, createRadioGroupScope] = (0, import_react_context2.createContextScope)(RADIO_GROUP_NAME, [
import_react_roving_focus.createRovingFocusGroupScope,
createRadioScope
]);
var useRovingFocusGroupScope = (0, import_react_roving_focus.createRovingFocusGroupScope)();
var useRadioScope = createRadioScope();
var [RadioGroupProvider, useRadioGroupContext] = createRadioGroupContext(RADIO_GROUP_NAME);
var RadioGroup = React2.forwardRef(
(props, forwardedRef) => {
const {
__scopeRadioGroup,
name,
defaultValue,
value: valueProp,
required = false,
disabled = false,
orientation,
dir,
loop = true,
onValueChange,
...groupProps
} = props;
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeRadioGroup);
const direction = (0, import_react_direction.useDirection)(dir);
const [value, setValue] = (0, import_react_use_controllable_state.useControllableState)({
prop: valueProp,
defaultProp: defaultValue,
onChange: onValueChange
});
return /*#__PURE__*/ $9yYIj$react.createElement($240483839a8a76fd$var$RadioGroupProvider, {
scope: __scopeRadioGroup,
name: name,
required: required,
disabled: disabled,
value: value,
onValueChange: setValue
}, /*#__PURE__*/ $9yYIj$react.createElement($9yYIj$radixuireactrovingfocus.Root, ($parcel$interopDefault($9yYIj$babelruntimehelpersextends))({
asChild: true
}, rovingFocusGroupScope, {
orientation: orientation,
dir: direction,
loop: loop
}), /*#__PURE__*/ $9yYIj$react.createElement($9yYIj$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($9yYIj$babelruntimehelpersextends))({
role: "radiogroup",
"aria-required": required,
"aria-orientation": orientation,
"data-disabled": disabled ? '' : undefined,
dir: direction
}, groupProps, {
ref: forwardedRef
}))));
});
/*#__PURE__*/ Object.assign($240483839a8a76fd$export$a98f0dcb43a68a25, {
displayName: $240483839a8a76fd$var$RADIO_GROUP_NAME
});
/* -------------------------------------------------------------------------------------------------
* RadioGroupItem
* -----------------------------------------------------------------------------------------------*/ const $240483839a8a76fd$var$ITEM_NAME = 'RadioGroupItem';
const $240483839a8a76fd$export$9f866c100ef519e4 = /*#__PURE__*/ $9yYIj$react.forwardRef((props, forwardedRef)=>{
const { __scopeRadioGroup: __scopeRadioGroup , disabled: disabled , ...itemProps } = props;
const context = $240483839a8a76fd$var$useRadioGroupContext($240483839a8a76fd$var$ITEM_NAME, __scopeRadioGroup);
const isDisabled = context.disabled || disabled;
const rovingFocusGroupScope = $240483839a8a76fd$var$useRovingFocusGroupScope(__scopeRadioGroup);
const radioScope = $240483839a8a76fd$var$useRadioScope(__scopeRadioGroup);
const ref = $9yYIj$react.useRef(null);
const composedRefs = $9yYIj$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref);
const checked = context.value === itemProps.value;
const isArrowKeyPressedRef = $9yYIj$react.useRef(false);
$9yYIj$react.useEffect(()=>{
const handleKeyDown = (event)=>{
if ($240483839a8a76fd$var$ARROW_KEYS.includes(event.key)) isArrowKeyPressedRef.current = true;
});
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
RadioGroupProvider,
{
scope: __scopeRadioGroup,
name,
required,
disabled,
value,
onValueChange: setValue,
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
RovingFocusGroup.Root,
{
asChild: true,
...rovingFocusGroupScope,
orientation,
dir: direction,
loop,
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
import_react_primitive2.Primitive.div,
{
role: "radiogroup",
"aria-required": required,
"aria-orientation": orientation,
"data-disabled": disabled ? "" : void 0,
dir: direction,
...groupProps,
ref: forwardedRef
}
)
}
)
}
);
}
);
RadioGroup.displayName = RADIO_GROUP_NAME;
var ITEM_NAME = "RadioGroupItem";
var RadioGroupItem = React2.forwardRef(
(props, forwardedRef) => {
const { __scopeRadioGroup, disabled, ...itemProps } = props;
const context = useRadioGroupContext(ITEM_NAME, __scopeRadioGroup);
const isDisabled = context.disabled || disabled;
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeRadioGroup);
const radioScope = useRadioScope(__scopeRadioGroup);
const ref = React2.useRef(null);
const composedRefs = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, ref);
const checked = context.value === itemProps.value;
const isArrowKeyPressedRef = React2.useRef(false);
React2.useEffect(() => {
const handleKeyDown = (event) => {
if (ARROW_KEYS.includes(event.key)) {
isArrowKeyPressedRef.current = true;
}
};
const handleKeyUp = ()=>isArrowKeyPressedRef.current = false
;
document.addEventListener('keydown', handleKeyDown);
document.addEventListener('keyup', handleKeyUp);
return ()=>{
document.removeEventListener('keydown', handleKeyDown);
document.removeEventListener('keyup', handleKeyUp);
const handleKeyUp = () => isArrowKeyPressedRef.current = false;
document.addEventListener("keydown", handleKeyDown);
document.addEventListener("keyup", handleKeyUp);
return () => {
document.removeEventListener("keydown", handleKeyDown);
document.removeEventListener("keyup", handleKeyUp);
};
}, []);
return /*#__PURE__*/ $9yYIj$react.createElement($9yYIj$radixuireactrovingfocus.Item, ($parcel$interopDefault($9yYIj$babelruntimehelpersextends))({
asChild: true
}, rovingFocusGroupScope, {
focusable: !isDisabled,
active: checked
}), /*#__PURE__*/ $9yYIj$react.createElement($ce74a64c62457efb$export$d7b12c4107be0d61, ($parcel$interopDefault($9yYIj$babelruntimehelpersextends))({
disabled: isDisabled,
required: context.required,
checked: checked
}, radioScope, itemProps, {
name: context.name,
ref: composedRefs,
onCheck: ()=>context.onValueChange(itemProps.value)
,
onKeyDown: $9yYIj$radixuiprimitive.composeEventHandlers((event)=>{
// According to WAI ARIA, radio groups don't activate items on enter keypress
if (event.key === 'Enter') event.preventDefault();
}),
onFocus: $9yYIj$radixuiprimitive.composeEventHandlers(itemProps.onFocus, ()=>{
var _ref$current;
/**
* Our `RovingFocusGroup` will focus the radio when navigating with arrow keys
* and we need to "check" it in that case. We click it to "check" it (instead
* of updating `context.value`) so that the radio change event fires.
*/ if (isArrowKeyPressedRef.current) (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.click();
})
})));
});
/*#__PURE__*/ Object.assign($240483839a8a76fd$export$9f866c100ef519e4, {
displayName: $240483839a8a76fd$var$ITEM_NAME
});
/* -------------------------------------------------------------------------------------------------
* RadioGroupIndicator
* -----------------------------------------------------------------------------------------------*/ const $240483839a8a76fd$var$INDICATOR_NAME = 'RadioGroupIndicator';
const $240483839a8a76fd$export$5fb54c671a65c88 = /*#__PURE__*/ $9yYIj$react.forwardRef((props, forwardedRef)=>{
const { __scopeRadioGroup: __scopeRadioGroup , ...indicatorProps } = props;
const radioScope = $240483839a8a76fd$var$useRadioScope(__scopeRadioGroup);
return /*#__PURE__*/ $9yYIj$react.createElement($ce74a64c62457efb$export$d35a9ffa9a04f9e7, ($parcel$interopDefault($9yYIj$babelruntimehelpersextends))({}, radioScope, indicatorProps, {
ref: forwardedRef
}));
});
/*#__PURE__*/ Object.assign($240483839a8a76fd$export$5fb54c671a65c88, {
displayName: $240483839a8a76fd$var$INDICATOR_NAME
});
/* ---------------------------------------------------------------------------------------------- */ const $240483839a8a76fd$export$be92b6f5f03c0fe9 = $240483839a8a76fd$export$a98f0dcb43a68a25;
const $240483839a8a76fd$export$6d08773d2e66f8f2 = $240483839a8a76fd$export$9f866c100ef519e4;
const $240483839a8a76fd$export$adb584737d712b70 = $240483839a8a76fd$export$5fb54c671a65c88;
}, []);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
RovingFocusGroup.Item,
{
asChild: true,
...rovingFocusGroupScope,
focusable: !isDisabled,
active: checked,
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Radio,
{
disabled: isDisabled,
required: context.required,
checked,
...radioScope,
...itemProps,
name: context.name,
ref: composedRefs,
onCheck: () => context.onValueChange(itemProps.value),
onKeyDown: (0, import_primitive2.composeEventHandlers)((event) => {
if (event.key === "Enter") event.preventDefault();
}),
onFocus: (0, import_primitive2.composeEventHandlers)(itemProps.onFocus, () => {
if (isArrowKeyPressedRef.current) ref.current?.click();
})
}
)
}
);
}
);
RadioGroupItem.displayName = ITEM_NAME;
var INDICATOR_NAME2 = "RadioGroupIndicator";
var RadioGroupIndicator = React2.forwardRef(
(props, forwardedRef) => {
const { __scopeRadioGroup, ...indicatorProps } = props;
const radioScope = useRadioScope(__scopeRadioGroup);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RadioIndicator, { ...radioScope, ...indicatorProps, ref: forwardedRef });
}
);
RadioGroupIndicator.displayName = INDICATOR_NAME2;
var Root2 = RadioGroup;
var Item2 = RadioGroupItem;
var Indicator = RadioGroupIndicator;
})();
//# sourceMappingURL=index.js.map
{
"name": "@radix-ui/react-radio-group",
"version": "1.1.4-rc.11",
"version": "1.2.0-rc.1",
"license": "MIT",

@@ -31,13 +31,12 @@ "exports": {

"dependencies": {
"@babel/runtime": "^7.13.10",
"@radix-ui/primitive": "1.0.1",
"@radix-ui/react-compose-refs": "1.0.1",
"@radix-ui/react-context": "1.0.1",
"@radix-ui/react-direction": "1.0.1",
"@radix-ui/react-presence": "1.0.1",
"@radix-ui/react-primitive": "1.0.3",
"@radix-ui/react-roving-focus": "1.0.5-rc.11",
"@radix-ui/react-use-controllable-state": "1.0.1",
"@radix-ui/react-use-previous": "1.0.1",
"@radix-ui/react-use-size": "1.0.1"
"@radix-ui/primitive": "1.1.0-rc.1",
"@radix-ui/react-compose-refs": "1.1.0-rc.1",
"@radix-ui/react-context": "1.1.0-rc.1",
"@radix-ui/react-direction": "1.1.0-rc.1",
"@radix-ui/react-presence": "1.1.0-rc.1",
"@radix-ui/react-primitive": "1.1.0-rc.1",
"@radix-ui/react-roving-focus": "1.1.0-rc.1",
"@radix-ui/react-use-controllable-state": "1.1.0-rc.1",
"@radix-ui/react-use-previous": "1.1.0-rc.1",
"@radix-ui/react-use-size": "1.1.0-rc.1"
},

@@ -44,0 +43,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc