mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-27 12:12:03 +08:00
[ui][text input] add asterisk to label for required fields
This commit is contained in:
@ -30,6 +30,9 @@ export default {
|
|||||||
placeholder: {
|
placeholder: {
|
||||||
control: 'text',
|
control: 'text',
|
||||||
},
|
},
|
||||||
|
required: {
|
||||||
|
control: 'boolean',
|
||||||
|
},
|
||||||
type: {
|
type: {
|
||||||
control: 'text',
|
control: 'text',
|
||||||
},
|
},
|
||||||
@ -111,6 +114,17 @@ export function Disabled() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function Required() {
|
||||||
|
return (
|
||||||
|
<TextInput
|
||||||
|
label="Required input"
|
||||||
|
placeholder="John Doe"
|
||||||
|
required={true}
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function Error() {
|
export function Error() {
|
||||||
const [value, setValue] = useState('1234');
|
const [value, setValue] = useState('1234');
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ function TextInput(
|
|||||||
id: idParam,
|
id: idParam,
|
||||||
isLabelHidden = false,
|
isLabelHidden = false,
|
||||||
label,
|
label,
|
||||||
|
required,
|
||||||
startIcon: StartIcon,
|
startIcon: StartIcon,
|
||||||
type = 'text',
|
type = 'text',
|
||||||
value,
|
value,
|
||||||
@ -80,6 +81,7 @@ function TextInput(
|
|||||||
)}
|
)}
|
||||||
htmlFor={id}>
|
htmlFor={id}>
|
||||||
{label}
|
{label}
|
||||||
|
{required && <span className="text-danger-500 not-sr-only"> *</span>}
|
||||||
</label>
|
</label>
|
||||||
<div className="relative mt-1">
|
<div className="relative mt-1">
|
||||||
{StartIcon && (
|
{StartIcon && (
|
||||||
@ -101,6 +103,7 @@ function TextInput(
|
|||||||
defaultValue={defaultValue}
|
defaultValue={defaultValue}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
id={id}
|
id={id}
|
||||||
|
required={required}
|
||||||
type={type}
|
type={type}
|
||||||
value={value != null ? value : undefined}
|
value={value != null ? value : undefined}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
|
Reference in New Issue
Block a user