Skip to content

Commit 0fca5eb

Browse files
authored
feat: allow to set data-* attributes (#221)
1 parent 9de3fa6 commit 0fca5eb

File tree

7 files changed

+32
-6
lines changed

7 files changed

+32
-6
lines changed

src/components/CalendarView/hooks/useCalendarProps.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {ButtonButtonProps} from '@gravity-ui/uikit';
55

66
import type {CalendarProps} from '../../Calendar/Calendar';
77
import {formatDateTime} from '../../utils/dates';
8+
import {filterDOMProps} from '../../utils/filterDOMProps';
89
import {i18n} from '../i18n';
910

1011
import type {CalendarLayout, CalendarState, RangeCalendarState} from './types';
@@ -29,12 +30,9 @@ export function useCalendarProps(props: CalendarProps, state: CalendarState | Ra
2930
});
3031

3132
const calendarProps: React.HTMLAttributes<HTMLElement> = {
33+
...filterDOMProps(props, {labelable: true}),
3234
role: 'group',
33-
id: props.id,
3435
'aria-label': [props['aria-label'], title].filter(Boolean).join(', '),
35-
'aria-labelledby': props['aria-labelledby'] || undefined,
36-
'aria-describedby': props['aria-describedby'] || undefined,
37-
'aria-details': props['aria-details'] || undefined,
3836
'aria-disabled': state.disabled || undefined,
3937
...focusWithinProps,
4038
};

src/components/DateField/DateField.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {TextInput, useFocusWithin} from '@gravity-ui/uikit';
66

77
import {block} from '../../utils/cn';
88
import {HiddenInput} from '../HiddenInput/HiddenInput';
9+
import {filterDOMProps} from '../utils/filterDOMProps';
910

1011
import {useDateFieldProps} from './hooks/useDateFieldProps';
1112
import type {DateFieldProps} from './hooks/useDateFieldProps';
@@ -27,8 +28,11 @@ export function DateField({className, ...props}: DateFieldProps) {
2728
},
2829
});
2930

31+
const DOMProps = filterDOMProps(props);
32+
delete DOMProps.id;
33+
3034
return (
31-
<div className={b(null, className)} style={props.style} {...focusWithinProps}>
35+
<div {...DOMProps} className={b(null, className)} style={props.style} {...focusWithinProps}>
3236
<TextInput
3337
{...inputProps}
3438
value={state.isEmpty && !isActive && props.placeholder ? '' : inputProps.value}

src/components/DatePicker/hooks/useDatePickerProps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {CalendarInstance, CalendarProps} from '../../Calendar';
99
import {useDateFieldProps} from '../../DateField';
1010
import type {DateFieldProps} from '../../DateField';
1111
import type {RangeValue} from '../../types';
12+
import {filterDOMProps} from '../../utils/filterDOMProps';
1213
import {getButtonSizeForInput} from '../../utils/getButtonSizeForInput';
1314
import {mergeProps} from '../../utils/mergeProps';
1415
import type {DatePickerProps} from '../DatePicker';
@@ -90,8 +91,12 @@ export function useDatePickerProps<T extends DateTime | RangeValue<DateTime>>(
9091

9192
const {t} = i18n.useTranslation();
9293

94+
const DOMProps = filterDOMProps(props);
95+
delete DOMProps.id;
96+
9397
return {
9498
groupProps: {
99+
...DOMProps,
95100
ref: groupRef,
96101
tabIndex: -1,
97102
role: 'group',

src/components/RangeDateField/RangeDateField.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {useDateFieldProps} from '../DateField/hooks/useDateFieldProps';
1010
import type {DateFieldProps} from '../DateField/hooks/useDateFieldProps';
1111
import {HiddenInput} from '../HiddenInput/HiddenInput';
1212
import type {RangeValue} from '../types';
13+
import {filterDOMProps} from '../utils/filterDOMProps';
1314

1415
import {useRangeDateFieldState} from './hooks/useRangeDateFieldState';
1516

@@ -37,8 +38,11 @@ export function RangeDateField({className, ...props}: RangeDateFieldProps) {
3738
},
3839
});
3940

41+
const DOMProps = filterDOMProps(props);
42+
delete DOMProps.id;
43+
4044
return (
41-
<div className={b(null, className)} style={props.style} {...focusWithinProps}>
45+
<div {...DOMProps} className={b(null, className)} style={props.style} {...focusWithinProps}>
4246
<TextInput
4347
{...inputProps}
4448
value={state.isEmpty && !isActive && props.placeholder ? '' : inputProps.value}

src/components/RelativeDateField/RelativeDateField.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
TextInputExtendProps,
2020
TextInputProps,
2121
} from '../types';
22+
import {filterDOMProps} from '../utils/filterDOMProps';
2223

2324
import {useRelativeDateFieldProps} from './hooks/useRelativeDateFieldProps';
2425
import {useRelativeDateFieldState} from './hooks/useRelativeDateFieldState';
@@ -65,8 +66,12 @@ export function RelativeDateField(props: RelativeDateFieldProps) {
6566
isDisabled: isMobile,
6667
});
6768

69+
const DOMProps = filterDOMProps(props);
70+
delete DOMProps.id;
71+
6872
return (
6973
<div
74+
{...DOMProps}
7075
role="group"
7176
className={b(null, props.className)}
7277
style={props.style}

src/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {useDateFieldProps} from '../../DateField';
88
import type {DateFieldProps} from '../../DateField';
99
import {getCalendarModes} from '../../DatePicker/utils';
1010
import {useRelativeDateFieldProps} from '../../RelativeDateField';
11+
import {filterDOMProps} from '../../utils/filterDOMProps';
1112
import {getButtonSizeForInput} from '../../utils/getButtonSizeForInput';
1213
import {mergeProps} from '../../utils/mergeProps';
1314
import type {RelativeDatePickerProps} from '../RelativeDatePicker';
@@ -136,8 +137,12 @@ export function useRelativeDatePickerProps(
136137

137138
const {t} = i18n.useTranslation();
138139

140+
const DOMProps = filterDOMProps(props);
141+
delete DOMProps.id;
142+
139143
return {
140144
groupProps: {
145+
...DOMProps,
141146
ref: groupRef,
142147
tabIndex: -1,
143148
role: 'group',

src/components/RelativeRangeDatePicker/RelativeRangeDatePicker.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {useControlledState, useFocusWithin, useMobile} from '@gravity-ui/uikit';
77
import {block} from '../../utils/cn';
88
import {HiddenInput} from '../HiddenInput/HiddenInput';
99
import type {Value} from '../RelativeDatePicker';
10+
import {filterDOMProps} from '../utils/filterDOMProps';
1011

1112
import {Control} from './components/Control/Control';
1213
import {PickerDialog} from './components/PickerDialog/PickerDialog';
@@ -43,8 +44,12 @@ export function RelativeRangeDatePicker(props: RelativeRangeDatePickerProps) {
4344
},
4445
});
4546

47+
const DOMProps = filterDOMProps(props);
48+
delete DOMProps.id;
49+
4650
return (
4751
<div
52+
{...DOMProps}
4853
ref={setAnchor}
4954
{...focusWithinProps}
5055
className={b(null, props.className)}

0 commit comments

Comments
 (0)