Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,10 @@

// Preset
&-presets {
display: flex;
flex-direction: column;
gap: 4px;
background: #ccccff;

ul {
margin: 0;
padding: 0;
list-style: none;
}
}
Comment on lines 175 to 180

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

补上预设按钮的样式重置。

这里把 li 换成原生 button 后,只改了容器布局,没有重置按钮自身样式。浏览器默认的边框、内边距、背景和字体会直接暴露出来,预设面板会出现明显的视觉回归,而且不同浏览器表现也不一致。

建议修改
   &-presets {
     display: flex;
     flex-direction: column;
     gap: 4px;
     background: `#ccccff`;
+
+    > button {
+      padding: 0;
+      font: inherit;
+      color: inherit;
+      text-align: start;
+      background: transparent;
+      border: 0;
+      cursor: pointer;
+    }
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
&-presets {
display: flex;
flex-direction: column;
gap: 4px;
background: #ccccff;
ul {
margin: 0;
padding: 0;
list-style: none;
}
}
&-presets {
display: flex;
flex-direction: column;
gap: 4px;
background: `#ccccff`;
> button {
padding: 0;
font: inherit;
color: inherit;
text-align: start;
background: transparent;
border: 0;
cursor: pointer;
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@assets/index.less` around lines 175 - 180, The preset button container in the
&-presets styles only sets layout, so the new native button element still shows
browser default border, padding, background, and font styles. Update the button
styling in the presets section of assets/index.less to reset the button
appearance (for example in the same ruleset that styles the preset items) so the
visual matches the old li-based UI consistently across browsers.


&-footer,
Expand Down
35 changes: 17 additions & 18 deletions src/PickerInput/Popup/PresetPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,23 @@ export default function PresetPanel<DateType extends object = any>(

return (
<div className={`${prefixCls}-presets`}>
<ul>
{presets.map(({ label, value }, index) => (
<li
key={index}
onClick={() => {
onClick(executeValue(value));
}}
onMouseEnter={() => {
onHover(executeValue(value));
}}
onMouseLeave={() => {
onHover(null);
}}
>
{label}
</li>
))}
</ul>
{presets.map(({ label, value }, index) => (
<button
key={index}
type="button"
onClick={() => {
onClick(executeValue(value));
}}
onMouseEnter={() => {
onHover(executeValue(value));
}}
onMouseLeave={() => {
onHover(null);
}}
Comment on lines +27 to +38

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since this PR focuses on improving keyboard navigation and accessibility, we should ensure that preset buttons also trigger the hover preview state when they receive focus via keyboard tab navigation. Adding onFocus and onBlur handlers will match the mouse hover behavior (onMouseEnter/onMouseLeave) for keyboard users.

        <button
          key={index}
          type="button"
          onClick={() => {
            onClick(executeValue(value));
          }}
          onMouseEnter={() => {
            onHover(executeValue(value));
          }}
          onMouseLeave={() => {
            onHover(null);
          }}
          onFocus={() => {
            onHover(executeValue(value));
          }}
          onBlur={() => {
            onHover(null);
          }}
        >

>
{label}
</button>
))}
</div>
);
}
4 changes: 3 additions & 1 deletion src/PickerInput/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export type PopupShowTimeConfig<DateType extends object = any> = Omit<
Pick<SharedTimeProps<DateType>, 'disabledTime'>;

export interface PopupProps<DateType extends object = any, PresetValue = DateType>
extends Pick<React.InputHTMLAttributes<HTMLDivElement>, 'onFocus' | 'onBlur'>,
extends
Pick<React.InputHTMLAttributes<HTMLDivElement>, 'onFocus' | 'onBlur'>,
FooterProps<DateType>,
PopupPanelProps<DateType> {
panelRender?: SharedPickerProps['panelRender'];
Expand Down Expand Up @@ -218,6 +219,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
<div
onMouseDown={onPanelMouseDown}
tabIndex={-1}
role="dialog"
className={clsx(
containerPrefixCls,
// Used for Today Button style, safe to remove if no need
Expand Down
4 changes: 4 additions & 0 deletions src/PickerInput/Selector/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElem
format?: string;
validateFormat: (value: string) => boolean;
active?: boolean;
open?: boolean;
/** Used for single picker only */
showActiveCls?: boolean;
suffixIcon?: React.ReactNode;
Expand All @@ -52,6 +53,7 @@ const Input = React.forwardRef<InputRef, InputProps>((props, ref) => {
const {
className,
active,
open,
showActiveCls = true,
suffixIcon,
format,
Expand Down Expand Up @@ -405,6 +407,8 @@ const Input = React.forwardRef<InputRef, InputProps>((props, ref) => {
<Component
ref={inputRef}
aria-invalid={invalid}
aria-haspopup="dialog"
aria-expanded={open}
autoComplete="off"
Comment on lines 407 to 412

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to ARIA specifications, the aria-expanded attribute is not supported on a standard textbox input element unless it has role="combobox". Adding role="combobox" ensures that screen readers correctly interpret and announce the expanded/collapsed state of the date picker popup.

Suggested change
<Component
ref={inputRef}
aria-invalid={invalid}
aria-haspopup="dialog"
aria-expanded={open}
autoComplete="off"
<Component
ref={inputRef}
role="combobox"
aria-invalid={invalid}
aria-haspopup="dialog"
aria-expanded={open}
autoComplete="off"

{...restProps}
onKeyDown={onSharedKeyDown}
Expand Down
2 changes: 2 additions & 0 deletions src/PickerInput/Selector/hooks/useInputProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export default function useInputProps<DateType extends object = any>(

active: activeIndex === index,

open,

helped: allHelp || (activeHelp && activeIndex === index),

disabled: getProp(disabled),
Expand Down
66 changes: 43 additions & 23 deletions src/PickerPanel/DatePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,40 @@ export default function DatePanel<DateType extends object = any>(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;
const prefixColumn = showPrefixColumn
? (date: DateType) => {
// >>> Additional check for disabled
const disabled = disabledDate?.(date, { type: 'week' });
const label = generateConfig.locale.getWeek(locale.locale, date);

return (
<td
key="week"
role="rowheader"
aria-label={`${locale.week} ${label}`}
className={clsx(cellPrefixCls, `${cellPrefixCls}-week`, {
[`${cellPrefixCls}-disabled`]: disabled,
})}
Expand All @@ -80,9 +102,7 @@ export default function DatePanel<DateType extends object = any>(props: DatePane
}
}}
>
<div className={`${cellPrefixCls}-inner`}>
{generateConfig.locale.getWeek(locale.locale, date)}
</div>
<div className={`${cellPrefixCls}-inner`}>{label}</div>
</td>
);
}
Expand Down Expand Up @@ -132,13 +152,14 @@ export default function DatePanel<DateType extends object = any>(props: DatePane
return classObj;
};

// ========================= Header =========================
const monthsLocale: string[] =
locale.shortMonths ||
(generateConfig.locale.getShortMonths
? generateConfig.locale.getShortMonths(locale.locale)
: []);
const getCellAttributes = (date: DateType): React.TdHTMLAttributes<HTMLTableCellElement> => {
if (isSameDate(generateConfig, date, now)) {
return { 'aria-current': 'date' };
}
return {};
};

// ========================= Header =========================
const yearNode: React.ReactNode = (
<button
type="button"
Expand All @@ -147,14 +168,9 @@ export default function DatePanel<DateType extends object = any>(props: DatePane
onClick={() => {
onModeChange('year', pickerValue);
}}
tabIndex={-1}
className={`${prefixCls}-year-btn`}
>
{formatValue(pickerValue, {
locale,
format: locale.yearFormat,
generateConfig,
})}
{yearLabel}
</button>
);
const monthNode: React.ReactNode = (
Expand All @@ -165,20 +181,16 @@ export default function DatePanel<DateType extends object = any>(props: DatePane
onClick={() => {
onModeChange('month', pickerValue);
}}
tabIndex={-1}
className={`${prefixCls}-month-btn`}
>
{locale.monthFormat
? formatValue(pickerValue, {
locale,
format: locale.monthFormat,
generateConfig,
})
: monthsLocale[month]}
{monthLabel}
</button>
);

const monthYearNodes = locale.monthBeforeYear ? [monthNode, yearNode] : [yearNode, monthNode];
const tableLabel = locale.monthBeforeYear
? `${monthLabel} ${yearLabel}`
: `${yearLabel} ${monthLabel}`;

// ========================= Render =========================
return (
Expand All @@ -196,6 +208,12 @@ export default function DatePanel<DateType extends object = any>(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}
</PanelHeader>
Expand All @@ -213,8 +231,10 @@ export default function DatePanel<DateType extends object = any>(props: DatePane
getCellDate={getCellDate}
getCellText={getCellText}
getCellClassName={getCellClassName}
getCellAttributes={getCellAttributes}
prefixColumn={prefixColumn}
cellSelection={!isWeek}
tableLabel={tableLabel}
/>
</div>
</PanelContext.Provider>
Expand Down
14 changes: 12 additions & 2 deletions src/PickerPanel/DecadePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export default function DecadePanel<DateType extends object = any>(
};
};

const getCellAttributes = (date: DateType): React.TdHTMLAttributes<HTMLTableCellElement> => {
if (isSameDecade(generateConfig, date, generateConfig.getNow())) {
return { 'aria-current': 'date' };
}
return {};
};

// ======================== Disabled ========================
const mergedDisabledDate: DisabledDate<DateType> = disabledDate
? (currentDate, disabledInfo) => {
Expand All @@ -81,7 +88,7 @@ export default function DecadePanel<DateType extends object = any>(
: null;

// ========================= Header =========================
const yearNode = `${formatValue(startYearDate, {
const yearLabel = `${formatValue(startYearDate, {
locale,
format: locale.yearFormat,
generateConfig,
Expand All @@ -102,8 +109,9 @@ export default function DecadePanel<DateType extends object = any>(
// Limitation
getStart={getStartYear}
getEnd={getEndYear}
labels={{ superPrev: locale.previousCentury, superNext: locale.nextCentury }}
>
{yearNode}
{yearLabel}
</PanelHeader>

{/* Body */}
Expand All @@ -113,10 +121,12 @@ export default function DecadePanel<DateType extends object = any>(
colNum={3}
rowNum={4}
baseDate={baseDate}
tableLabel={yearLabel}
// Body
getCellDate={getCellDate}
getCellText={getCellText}
getCellClassName={getCellClassName}
getCellAttributes={getCellAttributes}
/>
</div>
</PanelContext.Provider>
Expand Down
24 changes: 17 additions & 7 deletions src/PickerPanel/MonthPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -23,6 +23,11 @@ export default function MonthPanel<DateType extends object = any>(
// ========================== 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[] =
Expand Down Expand Up @@ -52,6 +57,13 @@ export default function MonthPanel<DateType extends object = any>(
[`${prefixCls}-cell-in-view`]: true,
});

const getCellAttributes = (date: DateType): React.TdHTMLAttributes<HTMLTableCellElement> => {
if (isSameMonth(generateConfig, date, generateConfig.getNow())) {
return { 'aria-current': 'date' };
}
return {};
};

// ======================== Disabled ========================
const mergedDisabledDate: DisabledDate<DateType> = disabledDate
? (currentDate, disabledInfo) => {
Expand All @@ -75,14 +87,9 @@ export default function MonthPanel<DateType extends object = any>(
onClick={() => {
onModeChange('year');
}}
tabIndex={-1}
className={`${prefixCls}-year-btn`}
>
{formatValue(pickerValue, {
locale,
format: locale.yearFormat,
generateConfig,
})}
{yearLabel}
</button>
);

Expand All @@ -97,6 +104,7 @@ export default function MonthPanel<DateType extends object = any>(
// Limitation
getStart={(date) => generateConfig.setMonth(date, 0)}
getEnd={(date) => generateConfig.setMonth(date, 11)}
labels={{ superPrev: locale.previousYear, superNext: locale.nextYear }}
>
{yearNode}
</PanelHeader>
Expand All @@ -109,10 +117,12 @@ export default function MonthPanel<DateType extends object = any>(
colNum={3}
rowNum={4}
baseDate={baseDate}
tableLabel={yearLabel}
// Body
getCellDate={getCellDate}
getCellText={getCellText}
getCellClassName={getCellClassName}
getCellAttributes={getCellAttributes}
/>
</div>
</PanelContext.Provider>
Expand Down
Loading
Loading