mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 13:13:54 +08:00
[ui][radio list] remove disabled prop on radio list level
This commit is contained in:
@ -11,7 +11,6 @@ type Props<T> = Readonly<{
|
||||
children: ReadonlyArray<React.ReactElement<typeof RadioListItem>>;
|
||||
defaultValue?: T;
|
||||
description?: string;
|
||||
disabled?: boolean;
|
||||
isLabelHidden?: boolean;
|
||||
label: string;
|
||||
name?: string;
|
||||
@ -27,10 +26,9 @@ export default function RadioList<T>({
|
||||
children,
|
||||
defaultValue,
|
||||
description,
|
||||
disabled,
|
||||
orientation = 'vertical',
|
||||
isLabelHidden,
|
||||
name,
|
||||
orientation = 'vertical',
|
||||
label,
|
||||
required,
|
||||
value,
|
||||
@ -41,7 +39,7 @@ export default function RadioList<T>({
|
||||
<RadioListContext.Provider
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore TODO: Figure out how to type the onChange.
|
||||
value={{ defaultValue, disabled, name, onChange, value }}>
|
||||
value={{ defaultValue, name, onChange, value }}>
|
||||
<div>
|
||||
<div className={clsx(isLabelHidden ? 'sr-only' : 'mb-2')}>
|
||||
<label className="text-sm font-medium text-gray-900" id={labelId}>
|
||||
|
@ -3,7 +3,6 @@ import { createContext, useContext } from 'react';
|
||||
|
||||
type RadioListContextValue<T = unknown> = {
|
||||
defaultValue?: T;
|
||||
disabled?: boolean;
|
||||
name?: string;
|
||||
onChange?: (
|
||||
value: T,
|
||||
|
@ -12,14 +12,13 @@ type Props<T> = Readonly<{
|
||||
|
||||
export default function RadioListItem<T>({
|
||||
description,
|
||||
disabled: disabledProp = false,
|
||||
disabled = false,
|
||||
label,
|
||||
value,
|
||||
}: Props<T>) {
|
||||
const id = useId();
|
||||
const descriptionId = useId();
|
||||
const context = useRadioListContext();
|
||||
const disabled = context?.disabled ?? disabledProp;
|
||||
|
||||
return (
|
||||
<div
|
||||
@ -67,7 +66,10 @@ export default function RadioListItem<T>({
|
||||
</label>
|
||||
{description && (
|
||||
<p
|
||||
className={clsx(disabled ? 'text-slate-400' : 'text-slate-500')}
|
||||
className={clsx(
|
||||
'text-xs',
|
||||
disabled ? 'text-slate-400' : 'text-slate-500',
|
||||
)}
|
||||
id={descriptionId}>
|
||||
{description}
|
||||
</p>
|
||||
|
Reference in New Issue
Block a user