-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[RMmobile] Add Enter.key detection to the Title block #13500
Changes from 1 commit
55feb8a
e2346f1
92cc888
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 |
---|---|---|
|
@@ -12,13 +12,19 @@ import { withDispatch } from '@wordpress/data'; | |
import { withFocusOutside } from '@wordpress/components'; | ||
import { withInstanceId, compose } from '@wordpress/compose'; | ||
|
||
import { | ||
getDefaultBlockName, | ||
createBlock, | ||
} from '@wordpress/blocks'; | ||
|
||
class PostTitle extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.onChange = this.onChange.bind( this ); | ||
this.onSelect = this.onSelect.bind( this ); | ||
this.onUnselect = this.onUnselect.bind( this ); | ||
this.onEnter = this.onEnter.bind( this ); | ||
|
||
this.state = { | ||
isSelected: false, | ||
|
@@ -42,6 +48,14 @@ class PostTitle extends Component { | |
this.props.onUpdate( title ); | ||
} | ||
|
||
onEnter( ) { | ||
const { insertBlocksAfter } = this.props; | ||
if ( ! insertBlocksAfter ) { | ||
return; | ||
} | ||
insertBlocksAfter( [ createBlock( getDefaultBlockName() ) ] ); | ||
} | ||
|
||
render() { | ||
const { | ||
placeholder, | ||
|
@@ -55,8 +69,9 @@ class PostTitle extends Component { | |
<TextInput | ||
blurOnSubmit={ true } | ||
textAlignVertical="top" | ||
multiline | ||
numberOfLines={ 0 } | ||
multiline={ false } | ||
onSubmitEditing={ this.onEnter } | ||
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. For the comment above to work, this would become 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. Nice find @diegoreymendez! Tested here as well, and worked without problems 👍 I've updated this PR and main PR gb-mobile side. |
||
returnKeyType={ 'next' } | ||
onChangeText={ this.onChange } | ||
onFocus={ this.onSelect } | ||
placeholder={ decodedPlaceholder } | ||
|
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.
We could remove this method entirely and instead copy (and call) this method from the web .js sources.
I've tried it locally and it works and it works.
The advantage of using the same code as the web .js file is that it should make it easier for us to maintain this sourcefile if there are changes, or eventually unify it completely.