diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 3d1725c54fe71..91fa3bfd9aaad 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -75,7 +75,6 @@ function removeNativeProps( props ) { fontStyle, minWidth, maxWidth, - setRef, disableSuggestions, disableAutocorrection, ...restProps diff --git a/packages/block-editor/src/components/rich-text/index.native.js b/packages/block-editor/src/components/rich-text/index.native.js index 7739fcf357c90..1be6551302edf 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -94,14 +94,13 @@ export function RichTextWrapper( minWidth, maxWidth, onBlur, - setRef, disableSuggestions, disableAutocorrection, containerWidth, onEnter: onCustomEnter, ...props }, - forwardedRef + providedRef ) { const instanceId = useInstanceId( RichTextWrapper ); @@ -529,13 +528,13 @@ export function RichTextWrapper( [ onReplace, __unstableMarkAutomaticChange ] ); - const mergedRef = useMergeRefs( [ forwardedRef, fallbackRef ] ); + const mergedRef = useMergeRefs( [ providedRef, fallbackRef ] ); return ( { +PrivateRichText.isEmpty = ( value ) => { return ! value || value.length === 0; }; -ForwardedRichTextContainer.Content.defaultProps = { +PrivateRichText.Content.defaultProps = { format: 'string', value: '', }; -ForwardedRichTextContainer.Raw = RichText; +PrivateRichText.Raw = forwardRef( ( props, ref ) => ( + +) ); /** * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md */ -export default ForwardedRichTextContainer; +export default PrivateRichText; export { RichTextShortcut } from './shortcut'; export { RichTextToolbarButton } from './toolbar-button'; export { __unstableRichTextInputEvent } from './input-event'; diff --git a/packages/block-editor/src/components/rich-text/native/index.native.js b/packages/block-editor/src/components/rich-text/native/index.native.js index 7a775cad34648..8b4c871bda7bb 100644 --- a/packages/block-editor/src/components/rich-text/native/index.native.js +++ b/packages/block-editor/src/components/rich-text/native/index.native.js @@ -1222,8 +1222,8 @@ export class RichText extends Component { ref={ ( ref ) => { this._editor = ref; - if ( this.props.setRef ) { - this.props.setRef( ref ); + if ( this.props.nativeEditorRef ) { + this.props.nativeEditorRef( ref ); } } } style={ { diff --git a/packages/block-editor/src/private-apis.native.js b/packages/block-editor/src/private-apis.native.js index 7a0328eba2f6f..f99d523933106 100644 --- a/packages/block-editor/src/private-apis.native.js +++ b/packages/block-editor/src/private-apis.native.js @@ -5,6 +5,7 @@ import * as globalStyles from './components/global-styles'; import { ExperimentalBlockEditorProvider } from './components/provider'; import { getRichTextValues } from './components/rich-text/get-rich-text-values'; import { lock } from './lock-unlock'; +import { PrivateRichText } from './components/rich-text/'; /** * Private @wordpress/block-editor APIs. @@ -14,4 +15,5 @@ lock( privateApis, { ...globalStyles, ExperimentalBlockEditorProvider, getRichTextValues, + PrivateRichText, } ); diff --git a/packages/block-library/src/button/edit.native.js b/packages/block-library/src/button/edit.native.js index 214be33c7df2e..e975710f821e1 100644 --- a/packages/block-library/src/button/edit.native.js +++ b/packages/block-library/src/button/edit.native.js @@ -494,7 +494,7 @@ function ButtonEdit( props ) { ) } { - const { isBlockSelected, hasSelectedInnerBlock } = - select( blockEditorStore ); - return ( - hasSelectedInnerBlock( clientId, true ) || - isBlockSelected( clientId ) - ); - }, - [ clientId ] - ); - const blockProps = useBlockProps( { className: classNames( className, { [ `has-text-align-${ textAlign }` ]: textAlign, @@ -114,33 +103,27 @@ export default function QuoteEdit( { { innerBlocksProps.children } - { ( ! RichText.isEmpty( citation ) || hasSelection ) && ( - { - setAttributes( { - citation: nextCitation, - } ); - } } - __unstableMobileNoFocusOnMount - aria-label={ __( 'Quote citation' ) } - placeholder={ - // translators: placeholder text used for the - // citation - __( 'Add citation' ) - } - className="wp-block-quote__citation" - __unstableOnSplitAtEnd={ () => - insertBlocksAfter( - createBlock( getDefaultBlockName() ) - ) - } - { ...( ! isWebPlatform ? { textAlign } : {} ) } - /> - ) } + ); diff --git a/packages/block-library/src/quote/test/edit.native.js b/packages/block-library/src/quote/test/edit.native.js index d2f2aad6669f9..c7479f611fa8b 100644 --- a/packages/block-library/src/quote/test/edit.native.js +++ b/packages/block-library/src/quote/test/edit.native.js @@ -10,7 +10,6 @@ import { getEditorHtml, fireEvent, within, - waitFor, typeInRichText, } from 'test/helpers'; @@ -40,14 +39,9 @@ describe( 'Quote', () => { }, } ); - // Await inner blocks to be rendered - const citationBlock = await waitFor( () => - screen.getByPlaceholderText( 'Add citation' ) - ); // Act fireEvent.press( quoteBlock ); - // screen.debug(); let quoteTextInput = within( quoteBlock ).getByPlaceholderText( 'Start writing…' ); typeInRichText( quoteTextInput, 'A great statement.' ); @@ -61,6 +55,10 @@ describe( 'Quote', () => { 'Start writing…' )[ 1 ]; typeInRichText( quoteTextInput, 'Again.' ); + fireEvent.press( screen.getByLabelText( 'Navigate Up' ) ); + fireEvent.press( screen.getByLabelText( 'Add citation' ) ); + const citationBlock = + await screen.findByPlaceholderText( 'Add citation' ); const citationTextInput = within( citationBlock ).getByPlaceholderText( 'Add citation' ); typeInRichText( citationTextInput, 'A person' ); diff --git a/packages/block-library/src/utils/caption.js b/packages/block-library/src/utils/caption.js index 57f034c76c6ed..394e032291c6e 100644 --- a/packages/block-library/src/utils/caption.js +++ b/packages/block-library/src/utils/caption.js @@ -23,10 +23,8 @@ import { createBlock, getDefaultBlockName } from '@wordpress/blocks'; */ import { unlock } from '../lock-unlock'; -const { PrivateRichText: RichText } = unlock( blockEditorPrivateApis ); - export function Caption( { - key = 'caption', + attributeKey = 'caption', attributes, setAttributes, isSelected, @@ -36,9 +34,15 @@ export function Caption( { showToolbarButton = true, className, disableEditing, + tagName = 'figcaption', + addLabel = __( 'Add caption' ), + removeLabel = __( 'Remove caption' ), + icon = captionIcon, + ...props } ) { - const caption = attributes[ key ]; + const caption = attributes[ attributeKey ]; const prevCaption = usePrevious( caption ); + const { PrivateRichText: RichText } = unlock( blockEditorPrivateApis ); const isCaptionEmpty = RichText.isEmpty( caption ); const isPrevCaptionEmpty = RichText.isEmpty( prevCaption ); const [ showCaption, setShowCaption ] = useState( ! isCaptionEmpty ); @@ -74,24 +78,22 @@ export function Caption( { onClick={ () => { setShowCaption( ! showCaption ); if ( showCaption && caption ) { - setAttributes( { caption: undefined } ); + setAttributes( { + [ attributeKey ]: undefined, + } ); } } } - icon={ captionIcon } + icon={ icon } isPressed={ showCaption } - label={ - showCaption - ? __( 'Remove caption' ) - : __( 'Add caption' ) - } + label={ showCaption ? removeLabel : addLabel } /> ) } { showCaption && ( ! RichText.isEmpty( caption ) || isSelected ) && ( - setAttributes( { caption: value } ) + setAttributes( { [ attributeKey ]: value } ) } inlineToolbar __unstableOnSplitAtEnd={ () => @@ -110,6 +112,7 @@ export function Caption( { ) } disableEditing={ disableEditing } + { ...props } /> ) } diff --git a/packages/editor/src/components/post-title/index.native.js b/packages/editor/src/components/post-title/index.native.js index 2d90472af7200..dc7534c28a79f 100644 --- a/packages/editor/src/components/post-title/index.native.js +++ b/packages/editor/src/components/post-title/index.native.js @@ -164,7 +164,7 @@ class PostTitle extends Component { accessibilityHint={ __( 'Updates the title.' ) } > { await page.keyboard.type( 'one' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'two' ); - // Navigate to the citation to select the block. - await page.keyboard.press( 'ArrowRight' ); + await editor.clickBlockToolbarButton( + 'Select parent block: Quote' + ); await editor.clickBlockOptionsMenuItem( 'Ungroup' ); expect( await editor.getEditedPostContent() ).toBe( ` @@ -168,7 +169,10 @@ test.describe( 'Quote', () => { await page.keyboard.type( 'one' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'two' ); - await page.keyboard.press( 'ArrowRight' ); + await editor.clickBlockToolbarButton( + 'Select parent block: Quote' + ); + await editor.clickBlockToolbarButton( 'Add citation' ); await page.keyboard.type( 'cite' ); await editor.clickBlockOptionsMenuItem( 'Ungroup' ); expect( await editor.getEditedPostContent() ).toBe( @@ -191,7 +195,8 @@ test.describe( 'Quote', () => { page, } ) => { await editor.insertBlock( { name: 'core/quote' } ); - await page.keyboard.press( 'ArrowRight' ); + await page.keyboard.press( 'ArrowUp' ); + await editor.clickBlockToolbarButton( 'Add citation' ); await page.keyboard.type( 'cite' ); await editor.clickBlockOptionsMenuItem( 'Ungroup' ); expect( await editor.getEditedPostContent() ).toBe( @@ -211,7 +216,7 @@ test.describe( 'Quote', () => { } ) => { await editor.insertBlock( { name: 'core/quote' } ); // Select the quote - await page.keyboard.press( 'ArrowRight' ); + await page.keyboard.press( 'ArrowUp' ); await editor.clickBlockOptionsMenuItem( 'Ungroup' ); expect( await editor.getEditedPostContent() ).toBe( '' ); } ); @@ -238,7 +243,8 @@ test.describe( 'Quote', () => { await page.keyboard.type( 'one' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'two' ); - await page.keyboard.press( 'ArrowRight' ); + await editor.clickBlockToolbarButton( 'Select parent block: Quote' ); + await editor.clickBlockToolbarButton( 'Add citation' ); await page.keyboard.type( 'cite' ); await editor.transformBlockTo( 'core/pullquote' ); expect( await editor.getEditedPostContent() ).toBe( @@ -301,7 +307,8 @@ test.describe( 'Quote', () => { } ) => { await editor.insertBlock( { name: 'core/quote' } ); await page.keyboard.type( '1' ); - await page.keyboard.press( 'ArrowRight' ); + await page.keyboard.press( 'ArrowUp' ); + await editor.clickBlockToolbarButton( 'Add citation' ); await page.keyboard.type( '2' ); expect( await editor.getEditedPostContent() ).toBe( ` @@ -331,7 +338,8 @@ test.describe( 'Quote', () => { } ) => { await editor.insertBlock( { name: 'core/quote' } ); await page.keyboard.type( '1' ); - await page.keyboard.press( 'ArrowRight' ); + await page.keyboard.press( 'ArrowUp' ); + await editor.clickBlockToolbarButton( 'Add citation' ); await page.keyboard.type( '2' ); await pageUtils.pressKeys( 'Shift+ArrowUp' ); let error; diff --git a/test/e2e/specs/editor/plugins/block-variations.spec.js b/test/e2e/specs/editor/plugins/block-variations.spec.js index 9f12c987efd39..4c5488af4443f 100644 --- a/test/e2e/specs/editor/plugins/block-variations.spec.js +++ b/test/e2e/specs/editor/plugins/block-variations.spec.js @@ -133,7 +133,7 @@ test.describe( 'Block variations', () => { await page.keyboard.press( 'Enter' ); // Select the quote block. - await page.keyboard.press( 'ArrowDown' ); + await page.keyboard.press( 'ArrowUp' ); await expect( page diff --git a/test/e2e/specs/editor/plugins/inner-blocks-render-appender.spec.js b/test/e2e/specs/editor/plugins/inner-blocks-render-appender.spec.js index 9886bd00fe2b6..a76d6c6439e2e 100644 --- a/test/e2e/specs/editor/plugins/inner-blocks-render-appender.spec.js +++ b/test/e2e/specs/editor/plugins/inner-blocks-render-appender.spec.js @@ -94,6 +94,9 @@ test.describe( 'RenderAppender prop of InnerBlocks', () => { // Insert a quote block. await blockListBox.getByRole( 'option', { name: 'Quote' } ).click(); + await page.keyboard.press( 'ArrowUp' ); + await page.keyboard.press( 'ArrowUp' ); + // Verify if the custom block appender text changed as expected. await expect( dynamimcAppender.getByText( 'Single Blocks Appender' ) diff --git a/test/e2e/specs/editor/various/style-variation.spec.js b/test/e2e/specs/editor/various/style-variation.spec.js index cc13dd1ad9238..136b8284b1ecf 100644 --- a/test/e2e/specs/editor/various/style-variation.spec.js +++ b/test/e2e/specs/editor/various/style-variation.spec.js @@ -17,9 +17,6 @@ test.describe( 'adding blocks', () => { attributes: { value: '

Quote content

' }, } ); - // Select the quote block. - await page.keyboard.press( 'ArrowDown' ); - await editor.clickBlockToolbarButton( 'Quote' ); await page.click( 'role=menuitem[name="Plain"i]' ); diff --git a/test/native/setup.js b/test/native/setup.js index 54a416bd43660..4fd511f38e91b 100644 --- a/test/native/setup.js +++ b/test/native/setup.js @@ -81,6 +81,7 @@ jest.mock( '@wordpress/api-fetch', () => { jest.mock( '@wordpress/react-native-bridge', () => { return { addEventListener: jest.fn(), + logException: jest.fn(), mediaUploadSync: jest.fn(), removeEventListener: jest.fn(), requestBlockTypeImpressions: jest.fn( ( callback ) => {