Skip to content

Commit c80a06e

Browse files
author
Ben Fox
committed
Fix calendar focus when icon clicked. Otherwise default to keep input focus.
Update autogenerated docs
1 parent beaa53e commit c80a06e

File tree

5 files changed

+31
-73
lines changed

5 files changed

+31
-73
lines changed

components/component-docs.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5890,12 +5890,24 @@
58905890
"returns": null
58915891
},
58925892
{
5893-
"name": "openDialog",
5893+
"name": "openDialogFromIcon",
58945894
"docblock": null,
58955895
"modifiers": [],
58965896
"params": [],
58975897
"returns": null
58985898
},
5899+
{
5900+
"name": "openDialog",
5901+
"docblock": null,
5902+
"modifiers": [],
5903+
"params": [
5904+
{
5905+
"name": "isRequestFromIcon",
5906+
"type": null
5907+
}
5908+
],
5909+
"returns": null
5910+
},
58995911
{
59005912
"name": "parseDate",
59015913
"docblock": null,
@@ -5960,17 +5972,6 @@
59605972
"computed": false
59615973
}
59625974
},
5963-
"canInputMaintainFocus": {
5964-
"type": {
5965-
"name": "bool"
5966-
},
5967-
"required": false,
5968-
"description": "When `true`, clicking or typing in `Input` will not result in focus shifting away from `Input`",
5969-
"defaultValue": {
5970-
"value": "false",
5971-
"computed": false
5972-
}
5973-
},
59745975
"className": {
59755976
"type": {
59765977
"name": "union",

components/date-picker/__docs__/storybook-stories.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Datepicker from '../../date-picker';
88
import { DATE_PICKER } from '../../../utilities/constants';
99

1010
import Default from '../__examples__/default';
11-
import MaintainInputFocus from '../__examples__/maintain-input-focus'
1211
import IsoWeekdays from '../__examples__/iso-weekday';
1312
import CustomInput from '../__examples__/custom-input';
1413
import SnaphotDefault from '../__examples__/snapshot-default';
@@ -34,7 +33,6 @@ storiesOf(DATE_PICKER, module)
3433
.add('Default - Right to Left (RTL)', () =>
3534
makeRtl(<Default action={action} />)
3635
)
37-
.add('Maintain Input Focus', () => <MaintainInputFocus action={action} canInputMaintainFocus />)
3836
.add('ISO weekdays', () => <IsoWeekdays action={action} />)
3937
.add('Custom Input', () => <CustomInput action={action} />)
4038
.add('Inline menu', () => (

components/date-picker/__examples__/maintain-input-focus.jsx

Lines changed: 0 additions & 40 deletions
This file was deleted.

components/date-picker/date-picker.jsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ const propTypes = {
5252
* Aligns the right or left side of the menu with the respective side of the trigger. _Tested with snapshot testing._
5353
*/
5454
align: PropTypes.oneOf(['left', 'right']),
55-
/**
56-
* When `true`, clicking or typing in `Input` will not result in focus shifting away from `Input`
57-
*/
58-
canInputMaintainFocus: PropTypes.bool,
5955
/**
6056
* CSS classes to be added to tag with `slds-datepicker`. If you are looking for the outer DOM node (slds-dropdown-trigger), please review `triggerClassName`. _Tested with snapshot testing._
6157
*/
@@ -201,7 +197,6 @@ const defaultProps = {
201197
previousMonth: 'Previous month',
202198
year: 'Year',
203199
},
204-
canInputMaintainFocus: false,
205200
formatter(date) {
206201
return date
207202
? `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`
@@ -267,6 +262,7 @@ class Datepicker extends React.Component {
267262

268263
this.state = {
269264
isOpen: false,
265+
isOpenFromIcon: false,
270266
value: props.value,
271267
formattedValue: initDate || '',
272268
inputValue: initDate || '',
@@ -314,7 +310,7 @@ class Datepicker extends React.Component {
314310
this.props.assistiveTextPreviousMonth || assistiveText.previousMonth // eslint-disable-line react/prop-types
315311
}
316312
assistiveTextYear={assistiveText.year}
317-
canStealFocus={!this.props.canInputMaintainFocus}
313+
canFocusCalendar={this.state.isOpenFromIcon}
318314
id={this.getId()}
319315
isIsoWeekday={this.props.isIsoWeekday}
320316
monthLabels={
@@ -407,7 +403,9 @@ class Datepicker extends React.Component {
407403
aria-expanded={this.getIsOpen()}
408404
category="utility"
409405
name="event"
410-
onClick={this.openDialog}
406+
onClick={() => {
407+
this.openDialogFromIcon();
408+
}}
411409
type="button"
412410
/>
413411
),
@@ -548,7 +546,7 @@ class Datepicker extends React.Component {
548546
this.props.onOpen(event, { portal });
549547
}
550548

551-
if (this.selectedDateCell && !this.props.canInputMaintainFocus) {
549+
if (this.selectedDateCell && this.state.isOpenFromIcon) {
552550
this.selectedDateCell.focus();
553551
}
554552
};
@@ -559,15 +557,23 @@ class Datepicker extends React.Component {
559557
}
560558

561559
if (this.getIsOpen()) {
562-
this.setState({ isOpen: false });
560+
this.setState({ isOpen: false, isOpenFromIcon: false });
563561

564562
if (this.inputRef) {
565563
this.inputRef.focus();
566564
}
567565
}
568566
};
569567

570-
openDialog = () => {
568+
openDialogFromIcon = () => {
569+
this.setState({ isOpenFromIcon: true });
570+
this.openDialog(true);
571+
};
572+
573+
openDialog = (isRequestFromIcon = false) => {
574+
if (!isRequestFromIcon) {
575+
this.setState({ isOpenFromIcon: false });
576+
}
571577
if (this.props.onRequestOpen) {
572578
this.props.onRequestOpen();
573579
} else {

components/date-picker/private/calendar-wrapper.jsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DatepickerCalendarWrapper extends React.Component {
4343
/**
4444
* Whether or not the `CalendarWrapper` can steal focus from the main `Input`
4545
*/
46-
canStealFocus: PropTypes.bool.isRequired,
46+
canFocusCalendar: PropTypes.bool.isRequired,
4747
/**
4848
* CSS classes to be added to tag with `slds-datepicker`.
4949
*/
@@ -112,26 +112,21 @@ class DatepickerCalendarWrapper extends React.Component {
112112

113113
state = {
114114
initialDateForCalendarRender: this.props.selectedDate,
115-
isCalendarFocused: this.props.canStealFocus,
116115
};
117116

118117
handleCalendarBlur = (event, { direction }) => {
119118
if (direction === 'next' && this.previousMonthRef) {
120-
this.setState({ isCalendarFocused: false });
121119
if (this.props.onCalendarFocus) {
122120
this.props.onCalendarFocus(event, {
123121
direction,
124-
isCalendarFocused: false,
125122
ref: this.previousMonthRef,
126123
});
127124
}
128125
this.previousMonthRef.focus();
129126
} else if (direction === 'previous' && this.todayRef) {
130-
this.setState({ isCalendarFocused: false });
131127
if (this.props.onCalendarFocus) {
132128
this.props.onCalendarFocus(event, {
133129
direction,
134-
isCalendarFocused: false,
135130
ref: this.todayRef,
136131
});
137132
}
@@ -142,7 +137,6 @@ class DatepickerCalendarWrapper extends React.Component {
142137
handleFirstFocusableNodeKeyDown = (event) => {
143138
if (event.shiftKey && event.keyCode === KEYS.TAB) {
144139
EventUtil.trapEvent(event);
145-
this.setState({ isCalendarFocused: true });
146140
}
147141
};
148142

@@ -163,7 +157,6 @@ class DatepickerCalendarWrapper extends React.Component {
163157
handleLastFocusableNodeKeyDown = (event) => {
164158
if (!event.shiftKey && event.keyCode === KEYS.TAB) {
165159
EventUtil.trapEvent(event);
166-
this.setState({ isCalendarFocused: true });
167160
}
168161
};
169162

@@ -175,7 +168,7 @@ class DatepickerCalendarWrapper extends React.Component {
175168

176169
handleRequestFocusDate = (event, data) => {
177170
// will be called three times, due to re-render
178-
if (data.ref && this.state.isCalendarFocused) {
171+
if (data.ref && this.props.canFocusCalendar) {
179172
data.ref.focus();
180173
}
181174

0 commit comments

Comments
 (0)