Skip to content

Commit cb5c907

Browse files
authored
Merge pull request #476 from mashmatrix/support-slds-2-date-input-datepicker
Update `DateInput` and `Datepicker` for SLDS2
2 parents c92f98e + 6e27a16 commit cb5c907

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

src/scripts/DateInput.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export const DateInput = createFC<DateInputProps, { isFormElement: boolean }>(
322322
});
323323

324324
const formElemProps = {
325-
id,
325+
controlId: id,
326326
cols,
327327
label,
328328
required,
@@ -333,7 +333,16 @@ export const DateInput = createFC<DateInputProps, { isFormElement: boolean }>(
333333
};
334334
return (
335335
<FormElement {...formElemProps}>
336-
<div className={classnames(className, 'slds-dropdown-trigger')}>
336+
<div
337+
className={classnames(
338+
className,
339+
'slds-dropdown-trigger',
340+
'slds-dropdown-trigger_click',
341+
{
342+
'slds-is-open': opened,
343+
}
344+
)}
345+
>
337346
<div className='slds-input-has-icon slds-input-has-icon_right'>
338347
<Input
339348
inputRef={inputRef}

src/scripts/Datepicker.tsx

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -141,39 +141,44 @@ const DatepickerFilter: FC<DatepickerFilterProps> = (props) => {
141141
const onNextMonth = useEventCallback(() => onMonthChange(1));
142142
return (
143143
<div className='slds-datepicker__filter slds-grid'>
144-
<div className='slds-datepicker__filter_month slds-grid slds-grid_align-spread slds-size_2-of-3'>
144+
<div className='slds-datepicker__filter_month slds-grid slds-grid_align-spread slds-grow'>
145145
<div className='slds-align-middle'>
146146
<Button
147-
className='slds-align-middle'
148147
type='icon-container'
149148
icon='left'
150-
size='small'
151149
alt='Previous Month'
152150
onClick={onPrevMonth}
153151
/>
154152
</div>
155-
<h2 className='slds-align-middle'>{dayjs.monthsShort()[cal.month]}</h2>
153+
<h2
154+
className='slds-align-middle'
155+
aria-atomic='false'
156+
aria-live='polite'
157+
>
158+
{dayjs.monthsShort()[cal.month]}
159+
</h2>
156160
<div className='slds-align-middle'>
157161
<Button
158-
className='slds-align-middle'
159162
type='icon-container'
160163
icon='right'
161-
size='small'
162164
alt='Next Month'
163165
onClick={onNextMonth}
164166
/>
165167
</div>
166168
</div>
167-
<div className='slds-size_1-of-3'>
168-
<Select value={cal.year} onChange={onYearChange}>
169-
{new Array(11)
170-
.join('_')
171-
.split('_')
172-
.map((a, i) => {
173-
const year = cal.year + i - 5;
174-
return <Option key={year} label={String(year)} value={year} />;
175-
})}
176-
</Select>
169+
<div className='slds-shrink-none'>
170+
<label className='slds-assistive-text'>Pick a Year</label>
171+
<div className='slds-select_container'>
172+
<Select value={cal.year} onChange={onYearChange}>
173+
{new Array(11)
174+
.join('_')
175+
.split('_')
176+
.map((a, i) => {
177+
const year = cal.year + i - 5;
178+
return <Option key={year} label={String(year)} value={year} />;
179+
})}
180+
</Select>
181+
</div>
177182
</div>
178183
</div>
179184
);
@@ -196,7 +201,6 @@ type DatepickerDateProps = {
196201
selectedDate: string | undefined;
197202
today: string;
198203
date: CalendarDate;
199-
dayIndex: number;
200204
} & DatepickerHandlers;
201205

202206
/**
@@ -208,7 +212,6 @@ const DatepickerDate: FC<DatepickerDateProps> = (props) => {
208212
selectedDate,
209213
today,
210214
date,
211-
dayIndex,
212215
onDateKeyDown: onDateKeyDown_,
213216
onDateClick: onDateClick_,
214217
onDateFocus: onDateFocus_,
@@ -241,18 +244,20 @@ const DatepickerDate: FC<DatepickerDateProps> = (props) => {
241244
}
242245
const selected = date.value === selectedDate;
243246
const isToday = date.value === today;
247+
const isAdjacentMonth = date.month !== cal.month;
244248
const dateClassName = classnames({
245249
'slds-disabled-text': !enabled,
246250
'slds-is-selected': selected,
247251
'slds-is-today': isToday,
252+
'slds-day_adjacent-month': isAdjacentMonth,
248253
});
249254
return (
250255
<td
251256
className={dateClassName}
252-
headers={dayjs().weekday(dayIndex).format('ddd')}
253257
role='gridcell'
254-
aria-disabled={!enabled}
255258
aria-selected={selected}
259+
aria-current={isToday ? 'date' : undefined}
260+
aria-label={dayjs(date.value).format('D MMMM YYYY')}
256261
>
257262
<span
258263
className='slds-day'
@@ -292,12 +297,7 @@ const DatepickerMonth = forwardRef(
292297
onDateKeyDown,
293298
} = props;
294299
return (
295-
<table
296-
ref={ref}
297-
className='datepicker__month'
298-
role='grid'
299-
aria-labelledby='month'
300-
>
300+
<table ref={ref} className='slds-datepicker__month' role='grid'>
301301
<thead>
302302
<tr>
303303
{dayjs.weekdaysMin(true).map((wd, i) => (
@@ -489,6 +489,7 @@ export const Datepicker: FC<DatepickerProps> = (props) => {
489489
className={datepickerClassNames}
490490
ref={elementRef}
491491
tabIndex={-1}
492+
role='dialog'
492493
aria-hidden={false}
493494
onBlur={onBlur}
494495
onKeyDown={onKeyDown}

0 commit comments

Comments
 (0)