Skip to content

Commit 59af1b1

Browse files
committed
wip
1 parent bd81b05 commit 59af1b1

14 files changed

Lines changed: 49 additions & 8 deletions

File tree

src/calendar/grid/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,24 @@ export interface GridProps {
4747
renderDateAnnouncement: (date: Date, isOnCurrentDate: boolean) => string;
4848
isSameDate: (date: Date, baseDate: Date) => boolean;
4949
onGridKeyDownHandler: (event: React.KeyboardEvent<HTMLElement>) => void;
50+
referrerId?: string;
5051
}
5152

5253
interface GridCellProps extends TdHTMLAttributes<HTMLTableCellElement> {
5354
disabledReason?: string;
55+
referrerId?: string;
5456
}
5557

5658
const GridCell = forwardRef((props: GridCellProps, focusedDateRef: React.Ref<HTMLTableCellElement>) => {
57-
const { disabledReason, ...rest } = props;
59+
const { disabledReason, referrerId, ...rest } = props;
5860
const isDisabledWithReason = !!disabledReason;
5961
const { targetProps, descriptionEl } = useHiddenDescription(disabledReason);
60-
const ref = useRef<HTMLTableCellElement>(null);
62+
const cellRef = useRef<HTMLTableCellElement>(null);
6163
const [showTooltip, setShowTooltip] = useState(false);
6264

6365
return (
6466
<td
65-
ref={useMergeRefs(focusedDateRef, ref)}
67+
ref={useMergeRefs(focusedDateRef, cellRef)}
6668
{...(isDisabledWithReason ? targetProps : {})}
6769
{...rest}
6870
onFocus={() => (isDisabledWithReason ? setShowTooltip(true) : undefined)}
@@ -77,9 +79,10 @@ const GridCell = forwardRef((props: GridCellProps, focusedDateRef: React.Ref<HTM
7779
{showTooltip && (
7880
<Tooltip
7981
className={styles['disabled-reason-tooltip']}
80-
getTrack={() => ref.current}
82+
getTrack={() => cellRef.current}
8183
content={disabledReason!}
8284
onEscape={() => setShowTooltip(false)}
85+
referrerId={referrerId}
8386
/>
8487
)}
8588
</>
@@ -105,6 +108,7 @@ export default function Grid({
105108
renderDateAnnouncement,
106109
isSameDate,
107110
onGridKeyDownHandler,
111+
referrerId,
108112
}: GridProps) {
109113
const focusedDateRef = useRef<HTMLTableCellElement>(null);
110114

@@ -166,6 +170,7 @@ export default function Grid({
166170
[styles['calendar-date-dense']]: denseGrid,
167171
})}
168172
disabledReason={isDisabledWithReason ? disabledReason : undefined}
173+
referrerId={referrerId}
169174
>
170175
<span className={styles['date-inner']} aria-hidden="true">
171176
{renderDate(date)}

src/calendar/internal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import { getBaseMonth } from './utils/navigation-month';
2626

2727
import styles from './styles.css.js';
2828

29+
type InternalCalendarProps = CalendarProps & InternalBaseComponentProps & { referrerId?: string };
30+
2931
export default function Calendar({
3032
value,
3133
locale = '',
@@ -39,11 +41,12 @@ export default function Calendar({
3941
__internalRootRef,
4042
i18nStrings,
4143
granularity = 'day',
44+
referrerId,
4245
previousMonthAriaLabel,
4346
nextMonthAriaLabel,
4447
todayAriaLabel,
4548
...rest
46-
}: CalendarProps & InternalBaseComponentProps) {
49+
}: InternalCalendarProps) {
4750
checkControlled('Calendar', 'value', value, 'onChange', onChange);
4851

4952
const baseProps = getBaseProps(rest);
@@ -188,6 +191,7 @@ export default function Calendar({
188191
renderDateAnnouncement={renderDateAnnouncement}
189192
isSameDate={isSameDate}
190193
onGridKeyDownHandler={onGridKeyDownHandler}
194+
referrerId={referrerId}
191195
/>
192196
</div>
193197
</div>

src/date-picker/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ const DatePicker = React.forwardRef(
180180

181181
baseProps.className = clsx(baseProps.className, styles.root, styles['date-picker-container']);
182182

183+
const referrerId = useUniqueId();
184+
console.log('referrerId', referrerId);
185+
183186
return (
184187
<div {...baseProps} ref={mergedRef} onKeyDown={!disabled && !readOnly ? onWrapperKeyDownHandler : undefined}>
185188
{disabled || readOnly ? (
@@ -195,6 +198,7 @@ const DatePicker = React.forwardRef(
195198
expandToViewport={expandToViewport}
196199
scrollable={false}
197200
dropdownId={dropdownId}
201+
referrerId={referrerId}
198202
content={
199203
isDropDownOpen ? (
200204
<FocusLock className={styles['focus-lock']} autoFocus={true}>
@@ -220,6 +224,7 @@ const DatePicker = React.forwardRef(
220224
nextMonthAriaLabel: i18nStrings?.nextMonthAriaLabel ?? nextMonthAriaLabel,
221225
previousMonthAriaLabel: i18nStrings?.previousMonthAriaLabel ?? previousMonthAriaLabel,
222226
}}
227+
referrerId={referrerId}
223228
/>
224229
<InternalLiveRegion id={calendarDescriptionId} hidden={true} tagName="span">
225230
{getBaseDateLabel({ date: baseDate, granularity, locale: normalizedLocale })}

src/date-range-picker/calendar/grids/grid-cell.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import testutilStyles from '../../test-classes/styles.css.js';
1212

1313
interface GridCellProps extends TdHTMLAttributes<HTMLTableCellElement> {
1414
disabledReason?: string;
15+
referrerId?: string;
1516
}
1617

1718
export const GridCell = forwardRef((props: GridCellProps, focusedDateRef: React.Ref<HTMLTableCellElement>) => {
18-
const { disabledReason, ...rest } = props;
19+
const { disabledReason, referrerId, ...rest } = props;
1920
const isDisabledWithReason = !!disabledReason;
2021
const { targetProps, descriptionEl } = useHiddenDescription(disabledReason);
2122
const ref = useRef<HTMLTableCellElement>(null);
@@ -73,6 +74,7 @@ export const GridCell = forwardRef((props: GridCellProps, focusedDateRef: React.
7374
getTrack={() => ref.current}
7475
content={disabledReason!}
7576
onEscape={() => setShowTooltip(false)}
77+
referrerId={referrerId}
7678
/>
7779
)}
7880
</>

src/date-range-picker/calendar/grids/grid.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export function Grid({
8686
className,
8787
startOfWeek: rawStartOfWeek = 0,
8888
granularity = 'day',
89+
referrerId,
8990
}: GridProps) {
9091
const baseDateTime = baseDate?.getTime();
9192
const i18n = useInternalI18n('date-range-picker');
@@ -275,6 +276,7 @@ export function Grid({
275276
aria-disabled={!isEnabled}
276277
tabIndex={tabIndex}
277278
disabledReason={isDisabledWithReason ? disabledReason : undefined}
279+
referrerId={referrerId}
278280
{...handlers}
279281
>
280282
<span className={styles[`${granularity}-inner`]} aria-hidden="true">

src/date-range-picker/calendar/grids/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const Grids = ({
6262
headingIdPrefix,
6363
startOfWeek = 0,
6464
granularity = 'day',
65+
referrerId,
6566
}: SelectGridProps) => {
6667
const containerRef = useRef<HTMLDivElement>(null);
6768
const [gridHasFocus, setGridHasFocus] = useState(false);
@@ -196,6 +197,7 @@ export const Grids = ({
196197
className={testutilStyles['first-grid']}
197198
baseDate={addPages(baseDate, -1)}
198199
ariaLabelledby={`${headingIdPrefix}-prev${pageUnit}`}
200+
referrerId={referrerId}
199201
/>
200202
)}
201203
<Grid
@@ -204,6 +206,7 @@ export const Grids = ({
204206
className={testutilStyles['second-grid']}
205207
baseDate={baseDate}
206208
ariaLabelledby={`${headingIdPrefix}-current${pageUnit}`}
209+
referrerId={referrerId}
207210
/>
208211
</InternalSpaceBetween>
209212
</div>

src/date-range-picker/calendar/grids/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface GridProps extends GridBaseProps, Required<Pick<CalendarProps, '
3434
currentMonthAriaLabel?: string;
3535
startOfWeek?: DayIndex;
3636
todayAriaLabel?: string;
37+
referrerId?: string;
3738
}
3839

3940
export interface SelectGridProps extends GridBaseProps, Pick<CalendarProps, 'granularity'> {
@@ -53,4 +54,5 @@ export interface SelectGridProps extends GridBaseProps, Pick<CalendarProps, 'gra
5354
startOfWeek?: DayIndex;
5455
todayAriaLabel?: string;
5556
currentMonthAriaLabel?: string;
57+
referrerId?: string;
5658
}

src/date-range-picker/calendar/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default function DateRangePickerCalendar({
5252
dateInputFormat,
5353
customAbsoluteRangeControl,
5454
granularity = 'day',
55+
referrerId,
5556
}: DateRangePickerCalendarProps) {
5657
const isSingleGrid = useMobile();
5758
const isMonthPicker = granularity === 'month';
@@ -273,6 +274,7 @@ export default function DateRangePickerCalendar({
273274
selectedStartDate={value?.start?.date ? parseDate(value.start.date, !isMonthPicker) : null}
274275
selectedEndDate={value?.end?.date ? parseDate(value.end.date, !isMonthPicker) : null}
275276
headingIdPrefix={headingIdPrefix}
277+
referrerId={referrerId}
276278
/>
277279
</div>
278280

src/date-range-picker/calendar/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface DateRangePickerCalendarProps
5555
value: DateRangePickerProps.PendingAbsoluteValue;
5656
setValue: React.Dispatch<React.SetStateAction<DateRangePickerProps.PendingAbsoluteValue>>;
5757
i18nStrings?: RangeCalendarI18nStrings;
58+
referrerId?: string;
5859
}
5960

6061
export interface RangeInputsProps

src/date-range-picker/dropdown.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ interface DateRangePickerDropdownProps
6262
isSingleGrid: boolean;
6363
customAbsoluteRangeControl: DateRangePickerProps.AbsoluteRangeControl | undefined;
6464
renderRelativeRangeContent: DateRangePickerProps.RelativeRangeControl | undefined;
65+
referrerId?: string;
6566
}
6667

6768
export function DateRangePickerDropdown({
@@ -91,6 +92,7 @@ export function DateRangePickerDropdown({
9192
customRelativeRangeUnits,
9293
renderRelativeRangeContent,
9394
granularity = 'day',
95+
referrerId,
9496
}: DateRangePickerDropdownProps) {
9597
const i18n = useInternalI18n('date-range-picker');
9698
const isMonthPicker = granularity === 'month';
@@ -216,6 +218,7 @@ export function DateRangePickerDropdown({
216218
dateInputFormat={dateInputFormat}
217219
customAbsoluteRangeControl={customAbsoluteRangeControl}
218220
granularity={granularity}
221+
referrerId={referrerId}
219222
/>
220223
)}
221224

0 commit comments

Comments
 (0)