Skip to content

Commit

Permalink
feat: add onKeyPressEvent (#1754)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeandenDrijver98 authored Sep 16, 2020
1 parent 2a99535 commit ca8d77b
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ class Calendar extends React.Component {
*/
onDoubleClickEvent: PropTypes.func,

/**
* Callback fired when a focused calendar event recieves a key press.
*
* ```js
* (event: Object, e: SyntheticEvent) => void
* ```
*/
onKeyPressEvent: PropTypes.func,

/**
* Callback fired when dragging a selection in the Time views.
*
Expand Down Expand Up @@ -493,16 +502,16 @@ class Calendar extends React.Component {
* (date: Date, resourceId: (number|string)) => { className?: string, style?: Object }
* ```
*/
slotPropGetter: PropTypes.func,
/**
* Optionally provide a function that returns an object of props to be applied
* to the time-slot group node. Useful to dynamically change the sizing of time nodes.
* ```js
* () => { style?: Object }
* ```
*/
slotGroupPropGetter: PropTypes.func,
slotPropGetter: PropTypes.func,

/**
* Optionally provide a function that returns an object of props to be applied
* to the time-slot group node. Useful to dynamically change the sizing of time nodes.
* ```js
* () => { style?: Object }
* ```
*/
slotGroupPropGetter: PropTypes.func,

/**
* Optionally provide a function that returns an object of className or style props
Expand Down Expand Up @@ -784,8 +793,8 @@ class Calendar extends React.Component {
resourceIdAccessor,
resourceTitleAccessor,
eventPropGetter,
slotPropGetter,
slotGroupPropGetter,
slotPropGetter,
slotGroupPropGetter,
dayPropGetter,
view,
views,
Expand All @@ -804,9 +813,9 @@ class Calendar extends React.Component {
eventProp: (...args) =>
(eventPropGetter && eventPropGetter(...args)) || {},
slotProp: (...args) =>
(slotPropGetter && slotPropGetter(...args)) || {},
slotGroupProp: (...args) =>
(slotGroupPropGetter && slotGroupPropGetter(...args)) || {},
(slotPropGetter && slotPropGetter(...args)) || {},
slotGroupProp: (...args) =>
(slotGroupPropGetter && slotGroupPropGetter(...args)) || {},
dayProp: (...args) => (dayPropGetter && dayPropGetter(...args)) || {},
},
components: defaults(components[view] || {}, omit(components, names), {
Expand Down Expand Up @@ -930,6 +939,7 @@ class Calendar extends React.Component {
onDrillDown={this.handleDrillDown}
onSelectEvent={this.handleSelectEvent}
onDoubleClickEvent={this.handleDoubleClickEvent}
onKeyPressEvent={this.handleKeyPressEvent}
onSelectSlot={this.handleSelectSlot}
onShowMore={onShowMore}
/>
Expand Down Expand Up @@ -997,6 +1007,10 @@ class Calendar extends React.Component {
notify(this.props.onDoubleClickEvent, args)
}

handleKeyPressEvent = (...args) => {
notify(this.props.onKeyPressEvent, args)
}

handleSelectSlot = slotInfo => {
notify(this.props.onSelectSlot, slotInfo)
}
Expand Down
3 changes: 3 additions & 0 deletions src/DateContentRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class DateContentRow extends React.Component {
onSelectStart,
onSelectEnd,
onDoubleClick,
onKeyPress,
resourceId,
longPressThreshold,
isAllDay,
Expand All @@ -133,6 +134,7 @@ class DateContentRow extends React.Component {
components,
onSelect,
onDoubleClick,
onKeyPress,
resourceId,
slotMetrics: metrics,
}
Expand Down Expand Up @@ -200,6 +202,7 @@ DateContentRow.propTypes = {
onSelectEnd: PropTypes.func,
onSelectStart: PropTypes.func,
onDoubleClick: PropTypes.func,
onKeyPress: PropTypes.func,
dayPropGetter: PropTypes.func,

getNow: PropTypes.func.isRequired,
Expand Down
6 changes: 6 additions & 0 deletions src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class DayColumn extends React.Component {
selected={isSelected(event, selected)}
onClick={e => this._select(event, e)}
onDoubleClick={e => this._doubleClick(event, e)}
onKeyPress={e => this._keyPress(event, e)}
/>
)
})
Expand Down Expand Up @@ -371,6 +372,10 @@ class DayColumn extends React.Component {
_doubleClick = (...args) => {
notify(this.props.onDoubleClickEvent, args)
}

_keyPress = (...args) => {
notify(this.props.onKeyPressEvent, args)
}
}

DayColumn.propTypes = {
Expand Down Expand Up @@ -402,6 +407,7 @@ DayColumn.propTypes = {
onSelectSlot: PropTypes.func.isRequired,
onSelectEvent: PropTypes.func.isRequired,
onDoubleClickEvent: PropTypes.func.isRequired,
onKeyPressEvent: PropTypes.func.isRequired,

className: PropTypes.string,
dragThroughEvents: PropTypes.bool,
Expand Down
3 changes: 3 additions & 0 deletions src/EventCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class EventCell extends React.Component {
isAllDay,
onSelect,
onDoubleClick,
onKeyPress,
localizer,
continuesPrior,
continuesAfter,
Expand Down Expand Up @@ -69,6 +70,7 @@ class EventCell extends React.Component {
})}
onClick={e => onSelect && onSelect(event, e)}
onDoubleClick={e => onDoubleClick && onDoubleClick(event, e)}
onKeyPress={e => onKeyPress && onKeyPress(event, e)}
>
{typeof children === 'function' ? children(content) : content}
</div>
Expand All @@ -94,6 +96,7 @@ EventCell.propTypes = {

onSelect: PropTypes.func,
onDoubleClick: PropTypes.func,
onKeyPress: PropTypes.func,
}

export default EventCell
3 changes: 3 additions & 0 deletions src/EventRowMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {

onSelect: PropTypes.func,
onDoubleClick: PropTypes.func,
onKeyPress: PropTypes.func,
},

defaultProps: {
Expand All @@ -33,6 +34,7 @@ export default {
getters,
onSelect,
onDoubleClick,
onKeyPress,
localizer,
slotMetrics,
components,
Expand All @@ -50,6 +52,7 @@ export default {
components={components}
onSelect={onSelect}
onDoubleClick={onDoubleClick}
onKeyPress={onKeyPress}
continuesPrior={continuesPrior}
continuesAfter={continuesAfter}
slotStart={slotMetrics.first}
Expand Down
8 changes: 8 additions & 0 deletions src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class MonthView extends React.Component {
onShowMore={this.handleShowMore}
onSelect={this.handleSelectEvent}
onDoubleClick={this.handleDoubleClickEvent}
onKeyPress={this.handleKeyPressEvent}
onSelectSlot={this.handleSelectSlot}
longPressThreshold={longPressThreshold}
rtl={this.props.rtl}
Expand Down Expand Up @@ -220,6 +221,7 @@ class MonthView extends React.Component {
slotEnd={overlay.end}
onSelect={this.handleSelectEvent}
onDoubleClick={this.handleDoubleClickEvent}
onKeyPress={this.handleKeyPressEvent}
handleDragStart={this.props.handleDragStart}
/>
)}
Expand Down Expand Up @@ -257,6 +259,11 @@ class MonthView extends React.Component {
notify(this.props.onDoubleClickEvent, args)
}

handleKeyPressEvent = (...args) => {
this.clearSelection()
notify(this.props.onKeyPressEvent, args)
}

handleShowMore = (events, date, cell, slot, target) => {
const { popup, onDrillDown, onShowMore, getDrilldownView } = this.props
//cancel any pending selections so only the event click goes through.
Expand Down Expand Up @@ -331,6 +338,7 @@ MonthView.propTypes = {
onSelectSlot: PropTypes.func,
onSelectEvent: PropTypes.func,
onDoubleClickEvent: PropTypes.func,
onKeyPressEvent: PropTypes.func,
onShowMore: PropTypes.func,
onDrillDown: PropTypes.func,
getDrilldownView: PropTypes.func.isRequired,
Expand Down
3 changes: 3 additions & 0 deletions src/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Popup extends React.Component {
components,
onSelect,
onDoubleClick,
onKeyPress,
slotStart,
slotEnd,
localizer,
Expand Down Expand Up @@ -73,6 +74,7 @@ class Popup extends React.Component {
accessors={accessors}
components={components}
onDoubleClick={onDoubleClick}
onKeyPress={onKeyPress}
continuesPrior={dates.lt(accessors.end(event), slotStart, 'day')}
continuesAfter={dates.gte(accessors.start(event), slotEnd, 'day')}
slotStart={slotStart}
Expand Down Expand Up @@ -106,6 +108,7 @@ Popup.propTypes = {
localizer: PropTypes.object.isRequired,
onSelect: PropTypes.func,
onDoubleClick: PropTypes.func,
onKeyPress: PropTypes.func,
handleDragStart: PropTypes.func,
show: PropTypes.func,
slotStart: PropTypes.instanceOf(Date),
Expand Down
2 changes: 2 additions & 0 deletions src/TimeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export default class TimeGrid extends Component {
onSelectSlot={this.handleSelectAllDaySlot}
onSelectEvent={this.handleSelectAlldayEvent}
onDoubleClickEvent={this.props.onDoubleClickEvent}
onKeyPressEvent={this.props.onKeyPressEvent}
onDrillDown={this.props.onDrillDown}
getDrilldownView={this.props.getDrilldownView}
/>
Expand Down Expand Up @@ -338,6 +339,7 @@ TimeGrid.propTypes = {
onSelectStart: PropTypes.func,
onSelectEvent: PropTypes.func,
onDoubleClickEvent: PropTypes.func,
onKeyPressEvent: PropTypes.func,
onDrillDown: PropTypes.func,
getDrilldownView: PropTypes.func.isRequired,

Expand Down
2 changes: 2 additions & 0 deletions src/TimeGridEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function TimeGridEvent(props) {
getters,
onClick,
onDoubleClick,
onKeyPress,
components: { event: Event, eventWrapper: EventWrapper },
} = props
let title = accessors.title(event)
Expand All @@ -44,6 +45,7 @@ function TimeGridEvent(props) {
<div
onClick={onClick}
onDoubleClick={onDoubleClick}
onKeyPress={onKeyPress}
style={{
...userProps.style,
top: stringifyPercent(top),
Expand Down
3 changes: 3 additions & 0 deletions src/TimeGridHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class TimeGridHeader extends React.Component {
localizer={localizer}
onSelect={this.props.onSelectEvent}
onDoubleClick={this.props.onDoubleClickEvent}
onKeyPress={this.props.onKeyPressEvent}
onSelectSlot={this.props.onSelectSlot}
longPressThreshold={this.props.longPressThreshold}
/>
Expand Down Expand Up @@ -180,6 +181,7 @@ class TimeGridHeader extends React.Component {
localizer={localizer}
onSelect={this.props.onSelectEvent}
onDoubleClick={this.props.onDoubleClickEvent}
onKeyPress={this.props.onKeyPressEvent}
onSelectSlot={this.props.onSelectSlot}
longPressThreshold={this.props.longPressThreshold}
/>
Expand Down Expand Up @@ -212,6 +214,7 @@ TimeGridHeader.propTypes = {
onSelectSlot: PropTypes.func,
onSelectEvent: PropTypes.func,
onDoubleClickEvent: PropTypes.func,
onKeyPressEvent: PropTypes.func,
onDrillDown: PropTypes.func,
getDrilldownView: PropTypes.func.isRequired,
scrollRef: PropTypes.any,
Expand Down

0 comments on commit ca8d77b

Please sign in to comment.