diff --git a/assets/index.less b/assets/index.less index 48522d422..4d02a5f1d 100644 --- a/assets/index.less +++ b/assets/index.less @@ -173,13 +173,10 @@ // Preset &-presets { + display: flex; + flex-direction: column; + gap: 4px; background: #ccccff; - - ul { - margin: 0; - padding: 0; - list-style: none; - } } &-footer, diff --git a/src/PickerInput/Popup/PresetPanel.tsx b/src/PickerInput/Popup/PresetPanel.tsx index d145cdcc5..fc86ee896 100644 --- a/src/PickerInput/Popup/PresetPanel.tsx +++ b/src/PickerInput/Popup/PresetPanel.tsx @@ -23,24 +23,23 @@ export default function PresetPanel( return (
- + {presets.map(({ label, value }, index) => ( + + ))}
); } diff --git a/src/PickerInput/Popup/index.tsx b/src/PickerInput/Popup/index.tsx index f02810390..d96505f87 100644 --- a/src/PickerInput/Popup/index.tsx +++ b/src/PickerInput/Popup/index.tsx @@ -20,7 +20,8 @@ export type PopupShowTimeConfig = Omit< Pick, 'disabledTime'>; export interface PopupProps - extends Pick, 'onFocus' | 'onBlur'>, + extends + Pick, 'onFocus' | 'onBlur'>, FooterProps, PopupPanelProps { panelRender?: SharedPickerProps['panelRender']; @@ -218,6 +219,7 @@ export default function Popup(props: PopupProps boolean; active?: boolean; + open?: boolean; /** Used for single picker only */ showActiveCls?: boolean; suffixIcon?: React.ReactNode; @@ -52,6 +53,7 @@ const Input = React.forwardRef((props, ref) => { const { className, active, + open, showActiveCls = true, suffixIcon, format, @@ -405,6 +407,8 @@ const Input = React.forwardRef((props, ref) => { ( active: activeIndex === index, + open, + helped: allHelp || (activeHelp && activeIndex === index), disabled: getProp(disabled), diff --git a/src/PickerPanel/DatePanel/index.tsx b/src/PickerPanel/DatePanel/index.tsx index 42013ebff..c5955acd4 100644 --- a/src/PickerPanel/DatePanel/index.tsx +++ b/src/PickerPanel/DatePanel/index.tsx @@ -48,7 +48,26 @@ export default function DatePanel(props: DatePane const weekFirstDay = generateConfig.locale.getWeekFirstDay(locale.locale); const monthStartDate = generateConfig.setDate(pickerValue, 1); const baseDate = getWeekStartDate(locale.locale, generateConfig, monthStartDate); + + const yearLabel = formatValue(pickerValue, { + locale, + format: locale.yearFormat, + generateConfig, + }); + + const monthsLocale: string[] = + locale.shortMonths || + (generateConfig.locale.getShortMonths + ? generateConfig.locale.getShortMonths(locale.locale) + : []); const month = generateConfig.getMonth(pickerValue); + const monthLabel = locale.monthFormat + ? formatValue(pickerValue, { + locale, + format: locale.monthFormat, + generateConfig, + }) + : monthsLocale[month]; // =========================== PrefixColumn =========================== const showPrefixColumn = showWeek === undefined ? isWeek : showWeek; @@ -56,10 +75,13 @@ export default function DatePanel(props: DatePane ? (date: DateType) => { // >>> Additional check for disabled const disabled = disabledDate?.(date, { type: 'week' }); + const label = generateConfig.locale.getWeek(locale.locale, date); return ( (props: DatePane } }} > -
- {generateConfig.locale.getWeek(locale.locale, date)} -
+
{label}
); } @@ -132,13 +152,14 @@ export default function DatePanel(props: DatePane return classObj; }; - // ========================= Header ========================= - const monthsLocale: string[] = - locale.shortMonths || - (generateConfig.locale.getShortMonths - ? generateConfig.locale.getShortMonths(locale.locale) - : []); + const getCellAttributes = (date: DateType): React.TdHTMLAttributes => { + if (isSameDate(generateConfig, date, now)) { + return { 'aria-current': 'date' }; + } + return {}; + }; + // ========================= Header ========================= const yearNode: React.ReactNode = ( ); const monthNode: React.ReactNode = ( @@ -165,20 +181,16 @@ export default function DatePanel(props: DatePane onClick={() => { onModeChange('month', pickerValue); }} - tabIndex={-1} className={`${prefixCls}-month-btn`} > - {locale.monthFormat - ? formatValue(pickerValue, { - locale, - format: locale.monthFormat, - generateConfig, - }) - : monthsLocale[month]} + {monthLabel} ); const monthYearNodes = locale.monthBeforeYear ? [monthNode, yearNode] : [yearNode, monthNode]; + const tableLabel = locale.monthBeforeYear + ? `${monthLabel} ${yearLabel}` + : `${yearLabel} ${monthLabel}`; // ========================= Render ========================= return ( @@ -196,6 +208,12 @@ export default function DatePanel(props: DatePane clone = generateConfig.addMonth(clone, 1); return generateConfig.addDate(clone, -1); }} + labels={{ + superPrev: locale.previousYear, + prev: locale.previousMonth, + next: locale.nextMonth, + superNext: locale.nextYear, + }} > {monthYearNodes} @@ -213,8 +231,10 @@ export default function DatePanel(props: DatePane getCellDate={getCellDate} getCellText={getCellText} getCellClassName={getCellClassName} + getCellAttributes={getCellAttributes} prefixColumn={prefixColumn} cellSelection={!isWeek} + tableLabel={tableLabel} /> diff --git a/src/PickerPanel/DecadePanel/index.tsx b/src/PickerPanel/DecadePanel/index.tsx index 748015d9f..390736cc7 100644 --- a/src/PickerPanel/DecadePanel/index.tsx +++ b/src/PickerPanel/DecadePanel/index.tsx @@ -61,6 +61,13 @@ export default function DecadePanel( }; }; + const getCellAttributes = (date: DateType): React.TdHTMLAttributes => { + if (isSameDecade(generateConfig, date, generateConfig.getNow())) { + return { 'aria-current': 'date' }; + } + return {}; + }; + // ======================== Disabled ======================== const mergedDisabledDate: DisabledDate = disabledDate ? (currentDate, disabledInfo) => { @@ -81,7 +88,7 @@ export default function DecadePanel( : null; // ========================= Header ========================= - const yearNode = `${formatValue(startYearDate, { + const yearLabel = `${formatValue(startYearDate, { locale, format: locale.yearFormat, generateConfig, @@ -102,8 +109,9 @@ export default function DecadePanel( // Limitation getStart={getStartYear} getEnd={getEndYear} + labels={{ superPrev: locale.previousCentury, superNext: locale.nextCentury }} > - {yearNode} + {yearLabel} {/* Body */} @@ -113,10 +121,12 @@ export default function DecadePanel( colNum={3} rowNum={4} baseDate={baseDate} + tableLabel={yearLabel} // Body getCellDate={getCellDate} getCellText={getCellText} getCellClassName={getCellClassName} + getCellAttributes={getCellAttributes} /> diff --git a/src/PickerPanel/MonthPanel/index.tsx b/src/PickerPanel/MonthPanel/index.tsx index cfd22079f..d84517275 100644 --- a/src/PickerPanel/MonthPanel/index.tsx +++ b/src/PickerPanel/MonthPanel/index.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import type { DisabledDate, SharedPanelProps } from '../../interface'; -import { formatValue } from '../../utils/dateUtil'; +import { formatValue, isSameMonth } from '../../utils/dateUtil'; import { PanelContext, useInfo } from '../context'; import PanelBody from '../PanelBody'; import PanelHeader from '../PanelHeader'; @@ -23,6 +23,11 @@ export default function MonthPanel( // ========================== Base ========================== const [info] = useInfo(props, 'month'); const baseDate = generateConfig.setMonth(pickerValue, 0); + const yearLabel = formatValue(pickerValue, { + locale, + format: locale.yearFormat, + generateConfig, + }); // ========================= Month ========================== const monthsLocale: string[] = @@ -52,6 +57,13 @@ export default function MonthPanel( [`${prefixCls}-cell-in-view`]: true, }); + const getCellAttributes = (date: DateType): React.TdHTMLAttributes => { + if (isSameMonth(generateConfig, date, generateConfig.getNow())) { + return { 'aria-current': 'date' }; + } + return {}; + }; + // ======================== Disabled ======================== const mergedDisabledDate: DisabledDate = disabledDate ? (currentDate, disabledInfo) => { @@ -75,14 +87,9 @@ export default function MonthPanel( onClick={() => { onModeChange('year'); }} - tabIndex={-1} className={`${prefixCls}-year-btn`} > - {formatValue(pickerValue, { - locale, - format: locale.yearFormat, - generateConfig, - })} + {yearLabel} ); @@ -97,6 +104,7 @@ export default function MonthPanel( // Limitation getStart={(date) => generateConfig.setMonth(date, 0)} getEnd={(date) => generateConfig.setMonth(date, 11)} + labels={{ superPrev: locale.previousYear, superNext: locale.nextYear }} > {yearNode} @@ -109,10 +117,12 @@ export default function MonthPanel( colNum={3} rowNum={4} baseDate={baseDate} + tableLabel={yearLabel} // Body getCellDate={getCellDate} getCellText={getCellText} getCellClassName={getCellClassName} + getCellAttributes={getCellAttributes} /> diff --git a/src/PickerPanel/PanelBody.tsx b/src/PickerPanel/PanelBody.tsx index 34b6fe011..67e36a327 100644 --- a/src/PickerPanel/PanelBody.tsx +++ b/src/PickerPanel/PanelBody.tsx @@ -15,6 +15,7 @@ export interface PanelBodyProps { getCellDate: (date: DateType, offset: number) => DateType; getCellText: (date: DateType) => React.ReactNode; getCellClassName: (date: DateType) => Record; + getCellAttributes: (date: DateType) => React.TdHTMLAttributes; disabledDate?: DisabledDate; @@ -25,6 +26,7 @@ export interface PanelBodyProps { prefixColumn?: (date: DateType) => React.ReactNode; rowClassName?: (date: DateType) => string; cellSelection?: boolean; + tableLabel?: string; } export default function PanelBody(props: PanelBodyProps) { @@ -38,9 +40,11 @@ export default function PanelBody(props: PanelBod titleFormat, getCellText, getCellClassName, + getCellAttributes, headerCells, cellSelection = true, disabledDate, + tableLabel, } = props; const { @@ -118,6 +122,12 @@ export default function PanelBody(props: PanelBod }) : undefined; + const isSelected = + !hoverRangeValue && + // WeekPicker use row instead + type !== 'week' && + matchValues(currentDate); + // Render const inner =
{getCellText(currentDate)}
; @@ -125,6 +135,11 @@ export default function PanelBody(props: PanelBod @@ -133,11 +148,7 @@ export default function PanelBody(props: PanelBod [`${cellPrefixCls}-in-range`]: inRange && !rangeStart && !rangeEnd, [`${cellPrefixCls}-range-start`]: rangeStart, [`${cellPrefixCls}-range-end`]: rangeEnd, - [`${prefixCls}-cell-selected`]: - !hoverRangeValue && - // WeekPicker use row instead - type !== 'week' && - matchValues(currentDate), + [`${prefixCls}-cell-selected`]: isSelected, ...getCellClassName(currentDate), })} style={styles.item} @@ -176,7 +187,7 @@ export default function PanelBody(props: PanelBod } rows.push( - + {rowNode} , ); @@ -185,9 +196,14 @@ export default function PanelBody(props: PanelBod // ============================== Render ============================== return (
- +
{headerCells && ( - + {headerCells} )} diff --git a/src/PickerPanel/PanelHeader.tsx b/src/PickerPanel/PanelHeader.tsx index 407489a59..f94919619 100644 --- a/src/PickerPanel/PanelHeader.tsx +++ b/src/PickerPanel/PanelHeader.tsx @@ -7,6 +7,13 @@ const HIDDEN_STYLE: React.CSSProperties = { visibility: 'hidden', }; +interface PanelHeaderLabels { + superPrev?: string; + prev?: string; + next?: string; + superNext?: string; +} + export interface HeaderProps { offset?: (distance: number, date: DateType) => DateType; superOffset?: (distance: number, date: DateType) => DateType; @@ -16,6 +23,8 @@ export interface HeaderProps { getStart?: (date: DateType) => DateType; getEnd?: (date: DateType) => DateType; + labels?: PanelHeaderLabels; + children?: React.ReactNode; } @@ -28,6 +37,8 @@ function PanelHeader(props: HeaderProps) { getStart, getEnd, + labels, + children, } = props; @@ -124,9 +135,8 @@ function PanelHeader(props: HeaderProps) { {superOffset && ( ); @@ -65,6 +72,7 @@ export default function QuarterPanel( // Limitation getStart={(date) => generateConfig.setMonth(date, 0)} getEnd={(date) => generateConfig.setMonth(date, 11)} + labels={{ superPrev: locale.previousYear, superNext: locale.nextYear }} > {yearNode} @@ -76,10 +84,12 @@ export default function QuarterPanel( colNum={4} rowNum={1} baseDate={baseDate} + tableLabel={yearLabel} // Body getCellDate={getCellDate} getCellText={getCellText} getCellClassName={getCellClassName} + getCellAttributes={getCellAttributes} /> diff --git a/src/PickerPanel/YearPanel/index.tsx b/src/PickerPanel/YearPanel/index.tsx index ae7e42811..9b242745a 100644 --- a/src/PickerPanel/YearPanel/index.tsx +++ b/src/PickerPanel/YearPanel/index.tsx @@ -35,6 +35,17 @@ export default function YearPanel( const endYearDate = getEndYear(pickerValue); const baseDate = generateConfig.addYear(startYearDate, -1); + const startYearLabel = formatValue(startYearDate, { + locale, + format: locale.yearFormat, + generateConfig, + }); + const endYearLabel = formatValue(endYearDate, { + locale, + format: locale.yearFormat, + generateConfig, + }); + const decadeLabel = `${startYearLabel}-${endYearLabel}`; // ========================= Cells ========================== const getCellDate = (date: DateType, offset: number) => { @@ -58,6 +69,13 @@ export default function YearPanel( }; }; + const getCellAttributes = (date: DateType): React.TdHTMLAttributes => { + if (isSameYear(generateConfig, date, generateConfig.getNow())) { + return { 'aria-current': 'date' }; + } + return {}; + }; + // ======================== Disabled ======================== const mergedDisabledDate: DisabledDate = disabledDate ? (currentDate, disabledInfo) => { @@ -81,20 +99,9 @@ export default function YearPanel( onClick={() => { onModeChange('decade'); }} - tabIndex={-1} className={`${prefixCls}-decade-btn`} > - {formatValue(startYearDate, { - locale, - format: locale.yearFormat, - generateConfig, - })} - - - {formatValue(endYearDate, { - locale, - format: locale.yearFormat, - generateConfig, - })} + {decadeLabel} ); @@ -109,6 +116,7 @@ export default function YearPanel( // Limitation getStart={getStartYear} getEnd={getEndYear} + labels={{ superPrev: locale.previousDecade, superNext: locale.nextDecade }} > {yearNode} @@ -121,10 +129,12 @@ export default function YearPanel( colNum={3} rowNum={4} baseDate={baseDate} + tableLabel={decadeLabel} // Body getCellDate={getCellDate} getCellText={getCellText} getCellClassName={getCellClassName} + getCellAttributes={getCellAttributes} /> diff --git a/tests/__snapshots__/panel.spec.tsx.snap b/tests/__snapshots__/panel.spec.tsx.snap index 34125971b..1a0895e8f 100644 --- a/tests/__snapshots__/panel.spec.tsx.snap +++ b/tests/__snapshots__/panel.spec.tsx.snap @@ -15,7 +15,6 @@ exports[`Picker.Panel append cell with cellRender in date 1`] = `
- + - + - + - + - + - + - +