-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(DateInput): add placeholder prop #8168
base: master
Are you sure you want to change the base?
Changes from 5 commits
5cfdfd5
c65e0a3
995627f
ed50f9c
56b121f
ce414d4
9200905
99b2476
4467867
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,10 @@ export interface DateInputProps | |
* Колбэк срабатывающий при нажатии на кнопку "Done". Используется совместно с флагом `enableTime`. | ||
*/ | ||
onApply?: (value?: Date) => void; | ||
/** | ||
* Текст, который будет отображаться в пустом поле ввода | ||
*/ | ||
placeholder?: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
учитывая, что ребятам хочется значение по умолчанию, то тут нужен Graceful degradation –
|
||
} | ||
|
||
const elementsConfig = (index: number) => { | ||
|
@@ -196,6 +200,7 @@ export const DateInput = ({ | |
minuteFieldTestId, | ||
id, | ||
onApply, | ||
placeholder, | ||
...props | ||
}: DateInputProps): React.ReactNode => { | ||
const daysRef = React.useRef<HTMLSpanElement>(null); | ||
|
@@ -301,6 +306,8 @@ export const DateInput = ({ | |
removeFocusFromField(); | ||
}, [onApply, onChange, removeFocusFromField, value]); | ||
|
||
const showPlaceholder = !open && !value && !!placeholder; | ||
|
||
return ( | ||
<FormField | ||
style={style} | ||
|
@@ -322,74 +329,82 @@ export const DateInput = ({ | |
onFocus={callMultiple(handleFieldEnter, onFocus)} | ||
{...props} | ||
> | ||
<VisuallyHidden | ||
id={id} | ||
Component="input" | ||
name={name} | ||
value={value ? format(value, enableTime ? "dd.MM.yyyy'T'HH:mm" : 'dd.MM.yyyy') : ''} | ||
/> | ||
<Text | ||
className={styles.input} | ||
onKeyDown={handleKeyDown} | ||
// Инцидент: в PR https://github.com/VKCOM/VKUI/pull/6649 стабильно ломается порядок стилей | ||
// из-за чего `.Typography--normalize` перебивает стили. | ||
normalize={false} | ||
Component="span" // для <span> нормализация не нужна | ||
> | ||
<InputLike | ||
length={2} | ||
getRootRef={daysRef} | ||
index={0} | ||
onElementSelect={setFocusedElement} | ||
value={internalValue[0]} | ||
label={changeDayLabel} | ||
data-testid={dayFieldTestId} | ||
/> | ||
<InputLikeDivider>.</InputLikeDivider> | ||
<InputLike | ||
length={2} | ||
getRootRef={monthsRef} | ||
index={1} | ||
onElementSelect={setFocusedElement} | ||
value={internalValue[1]} | ||
label={changeMonthLabel} | ||
data-testid={monthFieldTestId} | ||
/> | ||
<InputLikeDivider>.</InputLikeDivider> | ||
<InputLike | ||
length={4} | ||
getRootRef={yearsRef} | ||
index={2} | ||
onElementSelect={setFocusedElement} | ||
value={internalValue[2]} | ||
label={changeYearLabel} | ||
data-testid={yearFieldTestId} | ||
<div className={styles.wrapper}> | ||
<VisuallyHidden | ||
id={id} | ||
Component="input" | ||
placeholder={placeholder} | ||
name={name} | ||
value={value ? format(value, enableTime ? "dd.MM.yyyy'T'HH:mm" : 'dd.MM.yyyy') : ''} | ||
/> | ||
{enableTime && ( | ||
<React.Fragment> | ||
<InputLikeDivider className={styles.inputTimeDivider}> </InputLikeDivider> | ||
<InputLike | ||
length={2} | ||
getRootRef={hoursRef} | ||
index={3} | ||
onElementSelect={setFocusedElement} | ||
value={internalValue[3]} | ||
label={changeHoursLabel} | ||
data-testid={hourFieldTestId} | ||
/> | ||
<InputLikeDivider>:</InputLikeDivider> | ||
<InputLike | ||
length={2} | ||
getRootRef={minutesRef} | ||
index={4} | ||
onElementSelect={setFocusedElement} | ||
value={internalValue[4]} | ||
label={changeMinutesLabel} | ||
data-testid={minuteFieldTestId} | ||
/> | ||
</React.Fragment> | ||
<Text | ||
className={classNames(styles.input, showPlaceholder && styles.hidden)} | ||
onKeyDown={handleKeyDown} | ||
// Инцидент: в PR https://github.com/VKCOM/VKUI/pull/6649 стабильно ломается порядок стилей | ||
// из-за чего `.Typography--normalize` перебивает стили. | ||
normalize={false} | ||
Component="span" // для <span> нормализация не нужна | ||
> | ||
<InputLike | ||
length={2} | ||
getRootRef={daysRef} | ||
index={0} | ||
onElementSelect={setFocusedElement} | ||
value={internalValue[0]} | ||
label={changeDayLabel} | ||
data-testid={dayFieldTestId} | ||
/> | ||
<InputLikeDivider>.</InputLikeDivider> | ||
<InputLike | ||
length={2} | ||
getRootRef={monthsRef} | ||
index={1} | ||
onElementSelect={setFocusedElement} | ||
value={internalValue[1]} | ||
label={changeMonthLabel} | ||
data-testid={monthFieldTestId} | ||
/> | ||
<InputLikeDivider>.</InputLikeDivider> | ||
<InputLike | ||
length={4} | ||
getRootRef={yearsRef} | ||
index={2} | ||
onElementSelect={setFocusedElement} | ||
value={internalValue[2]} | ||
label={changeYearLabel} | ||
data-testid={yearFieldTestId} | ||
/> | ||
{enableTime && ( | ||
<React.Fragment> | ||
<InputLikeDivider className={styles.inputTimeDivider}> </InputLikeDivider> | ||
<InputLike | ||
length={2} | ||
getRootRef={hoursRef} | ||
index={3} | ||
onElementSelect={setFocusedElement} | ||
value={internalValue[3]} | ||
label={changeHoursLabel} | ||
data-testid={hourFieldTestId} | ||
/> | ||
<InputLikeDivider>:</InputLikeDivider> | ||
<InputLike | ||
length={2} | ||
getRootRef={minutesRef} | ||
index={4} | ||
onElementSelect={setFocusedElement} | ||
value={internalValue[4]} | ||
label={changeMinutesLabel} | ||
data-testid={minuteFieldTestId} | ||
/> | ||
</React.Fragment> | ||
)} | ||
</Text> | ||
{showPlaceholder && ( | ||
<Text className={styles.placeholder} aria-hidden> | ||
{placeholder} | ||
</Text> | ||
)} | ||
</Text> | ||
</div> | ||
{open && !disableCalendar && ( | ||
<Popper | ||
targetRef={rootRef} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
автопрефиксер сам выставит