diff --git a/packages/vkui/src/components/Calendar/Calendar.tsx b/packages/vkui/src/components/Calendar/Calendar.tsx index 0f8c28981dd..105f87c367e 100644 --- a/packages/vkui/src/components/Calendar/Calendar.tsx +++ b/packages/vkui/src/components/Calendar/Calendar.tsx @@ -14,13 +14,13 @@ import styles from './Calendar.module.css'; export interface CalendarProps extends Omit, 'onChange'>, - Pick, + Pick, Pick< CalendarHeaderProps, - | 'prevMonthAriaLabel' - | 'nextMonthAriaLabel' - | 'changeMonthAriaLabel' - | 'changeYearAriaLabel' + | 'prevMonthLabel' + | 'nextMonthLabel' + | 'changeMonthLabel' + | 'changeYearLabel' | 'onNextMonth' | 'onPrevMonth' | 'prevMonthIcon' @@ -35,7 +35,7 @@ export interface CalendarProps enableTime?: boolean; disablePickers?: boolean; doneButtonText?: string; - changeDayAriaLabel?: string; + changeDayLabel?: string; weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6; showNeighboringMonth?: boolean; size?: 's' | 'm'; @@ -77,14 +77,14 @@ export const Calendar = ({ doneButtonText, weekStartsOn = 1, disablePickers, - changeHoursAriaLabel, - changeMinutesAriaLabel, - prevMonthAriaLabel, - nextMonthAriaLabel, - changeMonthAriaLabel, - changeYearAriaLabel, + changeHoursLabel = 'Изменить час', + changeMinutesLabel = 'Изменить минуту', + prevMonthLabel = 'Предыдущий месяц', + nextMonthLabel = 'Следующий месяц', + changeMonthLabel = 'Изменить месяц', + changeYearLabel = 'Изменить год', showNeighboringMonth, - changeDayAriaLabel = 'Изменить день', + changeDayLabel = 'Изменить день', size = 'm', viewDate: externalViewDate, onHeaderChange, @@ -180,10 +180,10 @@ export const Calendar = ({ onPrevMonth={setPrevMonth} disablePickers={disablePickers || size === 's'} className={styles['Calendar__header']} - prevMonthAriaLabel={prevMonthAriaLabel} - nextMonthAriaLabel={nextMonthAriaLabel} - changeMonthAriaLabel={changeMonthAriaLabel} - changeYearAriaLabel={changeYearAriaLabel} + prevMonthLabel={prevMonthLabel} + nextMonthLabel={nextMonthLabel} + changeMonthLabel={changeMonthLabel} + changeYearLabel={changeYearLabel} prevMonthIcon={prevMonthIcon} nextMonthIcon={nextMonthIcon} prevMonthProps={prevMonthProps} @@ -195,7 +195,7 @@ export const Calendar = ({ weekStartsOn={weekStartsOn} isDayFocused={isDayFocused} tabIndex={0} - aria-label={changeDayAriaLabel} + aria-label={changeDayLabel} onKeyDown={handleKeyDown} onDayChange={onDayChange} isDayActive={isDayActive} @@ -215,8 +215,8 @@ export const Calendar = ({ onChange={onChange} onClose={onClose} doneButtonText={doneButtonText} - changeHoursAriaLabel={changeHoursAriaLabel} - changeMinutesAriaLabel={changeMinutesAriaLabel} + changeHoursLabel={changeHoursLabel} + changeMinutesLabel={changeMinutesLabel} isDayDisabled={minDateTime || maxDateTime ? isDayDisabled : undefined} /> diff --git a/packages/vkui/src/components/CalendarDay/CalendarDay.tsx b/packages/vkui/src/components/CalendarDay/CalendarDay.tsx index 096137b12e6..de6ad0b6bf9 100644 --- a/packages/vkui/src/components/CalendarDay/CalendarDay.tsx +++ b/packages/vkui/src/components/CalendarDay/CalendarDay.tsx @@ -3,6 +3,7 @@ import { classNames } from '@vkontakte/vkjs'; import { ENABLE_KEYBOARD_INPUT_EVENT_NAME } from '../../hooks/useKeyboardInputTracker'; import { useConfigProvider } from '../ConfigProvider/ConfigProviderContext'; import { Tappable, TappableElementProps } from '../Tappable/Tappable'; +import { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden'; import styles from './CalendarDay.module.css'; export type CalendarDayElementProps = Omit< @@ -50,7 +51,8 @@ export const CalendarDay = React.memo( sameMonth, size, className, - ...props + children, + ...restProps }: CalendarDayProps) => { const { locale } = useConfigProvider(); const ref = React.useRef(null); @@ -58,6 +60,13 @@ export const CalendarDay = React.memo( const handleEnter = React.useCallback(() => onEnter?.(day), [day, onEnter]); const handleLeave = React.useCallback(() => onLeave?.(day), [day, onLeave]); + const label = new Intl.DateTimeFormat(locale, { + weekday: 'long', + year: 'numeric', + month: 'long', + day: 'numeric', + }).format(day); + React.useEffect(() => { if (focused && ref.current) { ref.current.dispatchEvent(new Event(ENABLE_KEYBOARD_INPUT_EVENT_NAME, { bubbles: true })); @@ -66,7 +75,7 @@ export const CalendarDay = React.memo( }, [focused]); if (hidden) { - return
; + return
; } return ( @@ -86,18 +95,12 @@ export const CalendarDay = React.memo( hasActive={false} onClick={onClick} disabled={disabled} - aria-label={new Intl.DateTimeFormat(locale, { - weekday: 'long', - year: 'numeric', - month: 'long', - day: 'numeric', - }).format(day)} tabIndex={-1} getRootRef={ref} focusVisibleMode={active ? 'outside' : 'inside'} onEnter={handleEnter} onLeave={handleLeave} - {...props} + {...restProps} >
-
{day.getDate()}
+
+ {children ?? label} + {day.getDate()} +
diff --git a/packages/vkui/src/components/CalendarHeader/CalendarHeader.tsx b/packages/vkui/src/components/CalendarHeader/CalendarHeader.tsx index 6122143af94..2e5fe6bd9eb 100644 --- a/packages/vkui/src/components/CalendarHeader/CalendarHeader.tsx +++ b/packages/vkui/src/components/CalendarHeader/CalendarHeader.tsx @@ -14,6 +14,7 @@ import { CustomSelect } from '../CustomSelect/CustomSelect'; import { RootComponent } from '../RootComponent/RootComponent'; import { Tappable, TappableElementProps } from '../Tappable/Tappable'; import { Paragraph } from '../Typography/Paragraph/Paragraph'; +import { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden'; import styles from './CalendarHeader.module.css'; type ArrowMonthProps = Omit; @@ -24,10 +25,10 @@ export interface CalendarHeaderProps prevMonth?: boolean; nextMonth?: boolean; disablePickers?: boolean; - prevMonthAriaLabel?: string; - nextMonthAriaLabel?: string; - changeMonthAriaLabel?: string; - changeYearAriaLabel?: string; + prevMonthLabel?: string; + nextMonthLabel?: string; + changeMonthLabel?: string; + changeYearLabel?: string; prevMonthIcon?: React.ReactNode; nextMonthIcon?: React.ReactNode; prevMonthProps?: ArrowMonthProps; @@ -53,10 +54,10 @@ export const CalendarHeader = ({ onPrevMonth, prevMonthProps = {}, nextMonthProps = {}, - prevMonthAriaLabel = 'Предыдущий месяц', - nextMonthAriaLabel = 'Следующий месяц', - changeMonthAriaLabel = 'Изменить месяц', - changeYearAriaLabel = 'Изменить год', + prevMonthLabel, + nextMonthLabel, + changeMonthLabel, + changeYearLabel, prevMonthIcon = ( + + {prevMonthLabel}, {formatter.format(subMonths(viewDate, 1))} + {prevMonthIcon} @@ -163,7 +166,7 @@ export const CalendarHeader = ({ onChange={onMonthsChange} forceDropdownPortal={false} selectType="accent" - aria-label={changeMonthAriaLabel} + aria-label={changeMonthLabel} /> @@ -192,9 +195,11 @@ export const CalendarHeader = ({ nextMonthClassName, )} onClick={onNextMonth} - aria-label={`${nextMonthAriaLabel}, ${formatter.format(addMonths(viewDate, 1))}`} {...restNextMonthProps} > + + {nextMonthLabel}, {formatter.format(addMonths(viewDate, 1))} + {nextMonthIcon} diff --git a/packages/vkui/src/components/CalendarRange/CalendarRange.tsx b/packages/vkui/src/components/CalendarRange/CalendarRange.tsx index 730d5864656..958b7855e52 100644 --- a/packages/vkui/src/components/CalendarRange/CalendarRange.tsx +++ b/packages/vkui/src/components/CalendarRange/CalendarRange.tsx @@ -21,10 +21,10 @@ export interface CalendarRangeProps extends Omit, 'onChange'>, Pick< CalendarHeaderProps, - | 'prevMonthAriaLabel' - | 'nextMonthAriaLabel' - | 'changeMonthAriaLabel' - | 'changeYearAriaLabel' + | 'prevMonthLabel' + | 'nextMonthLabel' + | 'changeMonthLabel' + | 'changeYearLabel' | 'prevMonthIcon' | 'nextMonthIcon' >, @@ -33,7 +33,7 @@ export interface CalendarRangeProps disablePast?: boolean; disableFuture?: boolean; disablePickers?: boolean; - changeDayAriaLabel?: string; + changeDayLabel?: string; weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6; onChange?(value?: Array): void; shouldDisableDate?(value: Date): boolean; @@ -60,11 +60,11 @@ export const CalendarRange = ({ onClose, weekStartsOn = 1, disablePickers, - prevMonthAriaLabel, - nextMonthAriaLabel, - changeMonthAriaLabel, - changeYearAriaLabel, - changeDayAriaLabel = 'Изменить день', + prevMonthLabel = 'Предыдущий месяц', + nextMonthLabel = 'Следующий месяц', + changeMonthLabel = 'Изменить месяц', + changeYearLabel = 'Изменить год', + changeDayLabel = 'Изменить день', prevMonthIcon, nextMonthIcon, listenDayChangesForUpdate, @@ -187,10 +187,10 @@ export const CalendarRange = ({ onPrevMonth={setPrevMonth} disablePickers={disablePickers} className={styles['CalendarRange__header']} - prevMonthAriaLabel={prevMonthAriaLabel} - nextMonthAriaLabel={nextMonthAriaLabel} - changeMonthAriaLabel={changeMonthAriaLabel} - changeYearAriaLabel={changeYearAriaLabel} + prevMonthLabel={prevMonthLabel} + nextMonthLabel={nextMonthLabel} + changeMonthLabel={changeMonthLabel} + changeYearLabel={changeYearLabel} prevMonthIcon={prevMonthIcon} />
@@ -222,17 +222,17 @@ export const CalendarRange = ({ onNextMonth={setNextMonth} disablePickers={disablePickers} className={styles['CalendarRange__header']} - prevMonthAriaLabel={prevMonthAriaLabel} - nextMonthAriaLabel={nextMonthAriaLabel} - changeMonthAriaLabel={changeMonthAriaLabel} - changeYearAriaLabel={changeYearAriaLabel} + prevMonthLabel={prevMonthLabel} + nextMonthLabel={nextMonthLabel} + changeMonthLabel={changeMonthLabel} + changeYearLabel={changeYearLabel} nextMonthIcon={nextMonthIcon} /> { const localHours = isDayDisabled @@ -72,7 +72,7 @@ export const CalendarTime = ({ options={localHours} onChange={onHoursChange} forceDropdownPortal={false} - aria-label={changeHoursAriaLabel} + aria-label={changeHoursLabel} />
@@ -84,13 +84,13 @@ export const CalendarTime = ({ options={localMinutes} onChange={onMinutesChange} forceDropdownPortal={false} - aria-label={changeMinutesAriaLabel} + aria-label={changeMinutesLabel} />
- diff --git a/packages/vkui/src/components/DateInput/DateInput.tsx b/packages/vkui/src/components/DateInput/DateInput.tsx index c548c1bbb24..3dee7db4bd3 100644 --- a/packages/vkui/src/components/DateInput/DateInput.tsx +++ b/packages/vkui/src/components/DateInput/DateInput.tsx @@ -36,13 +36,13 @@ export interface DateInputProps | 'doneButtonText' | 'weekStartsOn' | 'disablePickers' - | 'changeHoursAriaLabel' - | 'changeMinutesAriaLabel' - | 'prevMonthAriaLabel' - | 'nextMonthAriaLabel' - | 'changeMonthAriaLabel' - | 'changeYearAriaLabel' - | 'changeDayAriaLabel' + | 'changeHoursLabel' + | 'changeMinutesLabel' + | 'prevMonthLabel' + | 'nextMonthLabel' + | 'changeMonthLabel' + | 'changeYearLabel' + | 'changeDayLabel' | 'showNeighboringMonth' | 'size' | 'viewDate' @@ -56,8 +56,8 @@ export interface DateInputProps FormFieldProps { calendarPlacement?: PlacementWithAuto; closeOnChange?: boolean; - clearFieldAriaLabel?: string; - showCalendarAriaLabel?: string; + clearFieldLabel?: string; + showCalendarLabel?: string; disableCalendar?: boolean; } @@ -123,17 +123,17 @@ export const DateInput = ({ disabled, onClick, onFocus, - prevMonthAriaLabel, - nextMonthAriaLabel, + prevMonthLabel = 'Предыдущий месяц', + nextMonthLabel = 'Следующий месяц', showNeighboringMonth, size, - changeMonthAriaLabel = 'Изменить месяц', - changeYearAriaLabel = 'Изменить год', - changeDayAriaLabel = 'Изменить день', - changeHoursAriaLabel = 'Изменить час', - changeMinutesAriaLabel = 'Изменить минуту', - clearFieldAriaLabel = 'Очистить поле', - showCalendarAriaLabel = 'Показать календарь', + changeMonthLabel = 'Изменить месяц', + changeYearLabel = 'Изменить год', + changeDayLabel = 'Изменить день', + changeHoursLabel = 'Изменить час', + changeMinutesLabel = 'Изменить минуту', + clearFieldLabel = 'Очистить поле', + showCalendarLabel = 'Показать календарь', viewDate, onHeaderChange, onNextMonth, @@ -223,11 +223,11 @@ export const DateInput = ({ getRootRef={handleRootRef} after={ value ? ( - + ) : ( - + ) @@ -249,7 +249,7 @@ export const DateInput = ({ index={0} onElementSelect={setFocusedElement} value={internalValue[0]} - aria-label={changeDayAriaLabel} + label={changeDayLabel} /> . . {enableTime && ( @@ -280,7 +280,7 @@ export const DateInput = ({ index={3} onElementSelect={setFocusedElement} value={internalValue[3]} - aria-label={changeHoursAriaLabel} + label={changeHoursLabel} /> : )} @@ -307,13 +307,13 @@ export const DateInput = ({ getRootRef={calendarRef} doneButtonText={doneButtonText} disablePickers={disablePickers} - changeHoursAriaLabel={changeHoursAriaLabel} - changeMinutesAriaLabel={changeMinutesAriaLabel} - prevMonthAriaLabel={prevMonthAriaLabel} - nextMonthAriaLabel={nextMonthAriaLabel} - changeMonthAriaLabel={changeMonthAriaLabel} - changeYearAriaLabel={changeYearAriaLabel} - changeDayAriaLabel={changeDayAriaLabel} + changeHoursLabel={changeHoursLabel} + changeMinutesLabel={changeMinutesLabel} + prevMonthLabel={prevMonthLabel} + nextMonthLabel={nextMonthLabel} + changeMonthLabel={changeMonthLabel} + changeYearLabel={changeYearLabel} + changeDayLabel={changeDayLabel} showNeighboringMonth={showNeighboringMonth} size={size} viewDate={viewDate} diff --git a/packages/vkui/src/components/DateRangeInput/DateRangeInput.tsx b/packages/vkui/src/components/DateRangeInput/DateRangeInput.tsx index 5da6ad8b729..78013dfe75a 100644 --- a/packages/vkui/src/components/DateRangeInput/DateRangeInput.tsx +++ b/packages/vkui/src/components/DateRangeInput/DateRangeInput.tsx @@ -34,11 +34,11 @@ export interface DateRangeInputProps | 'value' | 'weekStartsOn' | 'disablePickers' - | 'prevMonthAriaLabel' - | 'nextMonthAriaLabel' - | 'changeMonthAriaLabel' - | 'changeYearAriaLabel' - | 'changeDayAriaLabel' + | 'prevMonthLabel' + | 'nextMonthLabel' + | 'changeMonthLabel' + | 'changeYearLabel' + | 'changeDayLabel' | 'prevMonthIcon' | 'nextMonthIcon' >, @@ -46,14 +46,14 @@ export interface DateRangeInputProps FormFieldProps { calendarPlacement?: PlacementWithAuto; closeOnChange?: boolean; - clearFieldAriaLabel?: string; - showCalendarAriaLabel?: string; - changeStartDayAriaLabel?: string; - changeStartMonthAriaLabel?: string; - changeStartYearAriaLabel?: string; - changeEndDayAriaLabel?: string; - changeEndMonthAriaLabel?: string; - changeEndYearAriaLabel?: string; + clearFieldLabel?: string; + showCalendarLabel?: string; + changeStartDayLabel?: string; + changeStartMonthLabel?: string; + changeStartYearLabel?: string; + changeEndDayLabel?: string; + changeEndMonthLabel?: string; + changeEndYearLabel?: string; disableCalendar?: boolean; } @@ -117,19 +117,19 @@ export const DateRangeInput = ({ disabled, onClick, onFocus, - prevMonthAriaLabel, - nextMonthAriaLabel, - changeDayAriaLabel, - changeMonthAriaLabel, - changeYearAriaLabel, - changeStartDayAriaLabel = 'Изменить день начала', - changeStartMonthAriaLabel = 'Изменить месяц начала', - changeStartYearAriaLabel = 'Изменить год начала', - changeEndDayAriaLabel = 'Изменить день окончания', - changeEndMonthAriaLabel = 'Изменить месяц окончания', - changeEndYearAriaLabel = 'Изменить год окончания', - clearFieldAriaLabel = 'Очистить поле', - showCalendarAriaLabel = 'Показать календарь', + prevMonthLabel = 'Предыдущий месяц', + nextMonthLabel = 'Следующий месяц', + changeDayLabel = 'Изменить день', + changeMonthLabel = 'Изменить месяц', + changeYearLabel = 'Изменить год', + changeStartDayLabel = 'Изменить день начала', + changeStartMonthLabel = 'Изменить месяц начала', + changeStartYearLabel = 'Изменить год начала', + changeEndDayLabel = 'Изменить день окончания', + changeEndMonthLabel = 'Изменить месяц окончания', + changeEndYearLabel = 'Изменить год окончания', + clearFieldLabel = 'Очистить поле', + showCalendarLabel = 'Показать календарь', prevMonthIcon, nextMonthIcon, disableCalendar = false, @@ -236,11 +236,11 @@ export const DateRangeInput = ({ getRootRef={handleRootRef} after={ value ? ( - + ) : ( - + ) @@ -268,7 +268,7 @@ export const DateRangeInput = ({ index={0} onElementSelect={setFocusedElement} value={internalValue[0]} - aria-label={changeStartDayAriaLabel} + label={changeStartDayLabel} /> . . {' — '} . . {open && !disableCalendar && ( @@ -327,11 +327,11 @@ export const DateRangeInput = ({ onClose={closeCalendar} getRootRef={calendarRef} disablePickers={disablePickers} - prevMonthAriaLabel={prevMonthAriaLabel} - nextMonthAriaLabel={nextMonthAriaLabel} - changeMonthAriaLabel={changeMonthAriaLabel} - changeYearAriaLabel={changeYearAriaLabel} - changeDayAriaLabel={changeDayAriaLabel} + prevMonthLabel={prevMonthLabel} + nextMonthLabel={nextMonthLabel} + changeMonthLabel={changeMonthLabel} + changeYearLabel={changeYearLabel} + changeDayLabel={changeDayLabel} prevMonthIcon={prevMonthIcon} nextMonthIcon={nextMonthIcon} /> diff --git a/packages/vkui/src/components/InputLike/InputLike.tsx b/packages/vkui/src/components/InputLike/InputLike.tsx index 80571bcc28a..06873e04b72 100644 --- a/packages/vkui/src/components/InputLike/InputLike.tsx +++ b/packages/vkui/src/components/InputLike/InputLike.tsx @@ -1,14 +1,15 @@ import * as React from 'react'; import { callMultiple } from '../../lib/callMultiple'; import { stopPropagation } from '../../lib/utils'; -import { HTMLAttributesWithRootRef } from '../../types'; -import { RootComponent } from '../RootComponent/RootComponent'; +import { RootComponent, type RootComponentProps } from '../RootComponent/RootComponent'; +import { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden'; import styles from './InputLike.module.css'; -export interface InputLikeProps extends HTMLAttributesWithRootRef { +export interface InputLikeProps extends RootComponentProps { length: number; index: number; value?: string; + label?: string; onElementSelect?(index: number): void; } @@ -33,7 +34,8 @@ export const InputLike = ({ onElementSelect, onClick, onFocus, - ...props + label, + ...restProps }: InputLikeProps) => { const handleElementSelect = React.useCallback( (event: React.MouseEvent) => { @@ -50,8 +52,9 @@ export const InputLike = ({ tabIndex={0} onClick={callMultiple(onClick, handleElementSelect)} onFocus={callMultiple(stopPropagation, onFocus)} - {...props} + {...restProps} > + {label && {label}} {value?.slice(0, length - 1)} {value?.slice(length - 1) && (