-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customize DayPickerKeyboardShortcuts with renderKeyboardShortcutsButton #1576
Changes from 7 commits
4ad7be8
1b8465d
111494f
4e94f84
22d6a4b
92052b5
8b62e7b
ce25884
ba397af
116aacf
98fe176
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ const propTypes = forbidExtraProps({ | |
openKeyboardShortcutsPanel: PropTypes.func, | ||
closeKeyboardShortcutsPanel: PropTypes.func, | ||
phrases: PropTypes.shape(getPhrasePropTypes(DayPickerKeyboardShortcutsPhrases)), | ||
renderKeyboardShortcutsButton: PropTypes.func, | ||
}); | ||
|
||
const defaultProps = { | ||
|
@@ -31,6 +32,7 @@ const defaultProps = { | |
openKeyboardShortcutsPanel() {}, | ||
closeKeyboardShortcutsPanel() {}, | ||
phrases: DayPickerKeyboardShortcutsPhrases, | ||
renderKeyboardShortcutsButton: undefined, | ||
}; | ||
|
||
function getKeyboardShortcuts(phrases) { | ||
|
@@ -164,6 +166,7 @@ class DayPickerKeyboardShortcuts extends React.PureComponent { | |
closeKeyboardShortcutsPanel, | ||
styles, | ||
phrases, | ||
renderKeyboardShortcutsButton, | ||
} = this.props; | ||
|
||
const toggleButtonText = showKeyboardShortcutsPanel | ||
|
@@ -176,33 +179,36 @@ class DayPickerKeyboardShortcuts extends React.PureComponent { | |
|
||
return ( | ||
<div> | ||
<button | ||
ref={this.setShowKeyboardShortcutsButtonRef} | ||
{...css( | ||
styles.DayPickerKeyboardShortcuts_buttonReset, | ||
styles.DayPickerKeyboardShortcuts_show, | ||
bottomRight && styles.DayPickerKeyboardShortcuts_show__bottomRight, | ||
topRight && styles.DayPickerKeyboardShortcuts_show__topRight, | ||
topLeft && styles.DayPickerKeyboardShortcuts_show__topLeft, | ||
)} | ||
type="button" | ||
aria-label={toggleButtonText} | ||
onClick={this.onShowKeyboardShortcutsButtonClick} | ||
onMouseUp={(e) => { | ||
e.currentTarget.blur(); | ||
}} | ||
> | ||
<span | ||
{...css( | ||
styles.DayPickerKeyboardShortcuts_showSpan, | ||
bottomRight && styles.DayPickerKeyboardShortcuts_showSpan__bottomRight, | ||
topRight && styles.DayPickerKeyboardShortcuts_showSpan__topRight, | ||
topLeft && styles.DayPickerKeyboardShortcuts_showSpan__topLeft, | ||
)} | ||
> | ||
{ renderKeyboardShortcutsButton | ||
? renderKeyboardShortcutsButton() : ( | ||
<button | ||
ref={this.setShowKeyboardShortcutsButtonRef} | ||
{...css( | ||
styles.DayPickerKeyboardShortcuts_buttonReset, | ||
styles.DayPickerKeyboardShortcuts_show, | ||
bottomRight && styles.DayPickerKeyboardShortcuts_show__bottomRight, | ||
topRight && styles.DayPickerKeyboardShortcuts_show__topRight, | ||
topLeft && styles.DayPickerKeyboardShortcuts_show__topLeft, | ||
)} | ||
type="button" | ||
aria-label={toggleButtonText} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to pass in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused, what is being referred to as "custom button" here? Seems like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @monokrome But actually though, I just realized that I can pass in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! Thanks so much for explaining to me 😺 |
||
onClick={this.onShowKeyboardShortcutsButtonClick} | ||
onMouseUp={(e) => { | ||
e.currentTarget.blur(); | ||
}} | ||
> | ||
<span | ||
{...css( | ||
styles.DayPickerKeyboardShortcuts_showSpan, | ||
bottomRight && styles.DayPickerKeyboardShortcuts_showSpan__bottomRight, | ||
topRight && styles.DayPickerKeyboardShortcuts_showSpan__topRight, | ||
topLeft && styles.DayPickerKeyboardShortcuts_showSpan__topLeft, | ||
)} | ||
> | ||
? | ||
</span> | ||
</button> | ||
</span> | ||
</button> | ||
)} | ||
kypan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
{showKeyboardShortcutsPanel && ( | ||
<div | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,15 @@ describe('DayPickerKeyboardShortcuts', () => { | |
expect(mockEvent.currentTarget.blur.callCount).to.equal(1); | ||
}); | ||
}); | ||
|
||
describe('renderKeyboardShortcutsButton', () => { | ||
it('renders the provided button', () => { | ||
const props = { renderKeyboardShortcutsButton: () => (<button type="button">Success!</button>) }; | ||
const wrapper = shallow(<DayPickerKeyboardShortcuts {...props} />).dive(); | ||
const buttonWrapper = wrapper.children().find('button'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. possibly a more robust test would be to render a custom component, and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use case for renderKeyboardShortcutsButton is to literally send in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kypan i mean, the purpose is to ensure that whatever There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ljharb That definitely makes sense. I've updated it. Thanks! |
||
expect(buttonWrapper.text()).to.equal('Success!'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#DayPickerKeyboardShortcuts_panel', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nit, but I think that the code style in react-dates is to avoid ternaries by creating two conditions instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(in jsx in general)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, jsx curlies should have no bounding spaces inside them