Skip to content
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

[pull] trunk from WordPress:trunk #117

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function KeyboardShortcutsRegister() {
category: 'block',
description: __( 'Remove the selected block(s).' ),
keyCombination: {
modifier: 'access',
character: 'z',
modifier: 'shift',
character: 'backspace',
},
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isCollapsed, isEmpty } from '@wordpress/rich-text';

export default ( props ) => ( element ) => {
function onKeyDown( event ) {
const { keyCode } = event;
const { keyCode, shiftKey } = event;

if ( event.defaultPrevented ) {
return;
Expand All @@ -30,6 +30,11 @@ export default ( props ) => ( element ) => {
return;
}

// Exclude shift+backspace as they are shortcuts for deleting blocks.
if ( shiftKey ) {
return;
}

if ( onMerge ) {
onMerge( ! isReverse );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# TextAlignmentControl

The `TextAlignmentControl` component is responsible for rendering a control element that allows users to select and apply text alignment options to blocks or elements in the Gutenberg editor. It provides an intuitive interface for aligning text with options such as `left`, `center` and `right`.

## Usage

Renders the Text Alignment Component with `left`, `center` and `right` alignment options.

```jsx
import { TextAlignmentControl } from '@wordpress/block-editor';

const MyTextAlignmentControlComponent = () => (
<TextAlignmentControl
value={ textAlign }
onChange={ ( value ) => {
setAttributes( { textAlign: value } );
} }
/>
);
```

## Props

### `value`

- **Type:** `String`
- **Default:** `undefined`
- **Options:** `left`, `center`, `right`, `justify`

The current value of the text alignment setting. You may only choose from the `Options` listed above.

### `onChange`

- **Type:** `Function`

A callback function invoked when the text alignment value is changed via an interaction with any of the options. The function is called with the new alignment value (`left`, `center`, `right`) as the only argument.

### `className`

- **Type:** `String`

Class name to add to the control for custom styling.

### `options`

- **Type:** `Array`
- **Default:** [`left`, `center`, `right`]

An array that determines which alignment options will be available in the control. You can pass an array of alignment values to customize the options.
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ const SetAsHomepageModal = ( { items, closeModal } ) => {

export const useSetAsHomepageAction = () => {
const { pageOnFront, pageForPosts } = useSelect( ( select ) => {
const { getEntityRecord } = select( coreStore );
const siteSettings = getEntityRecord( 'root', 'site' );
const { getEntityRecord, canUser } = select( coreStore );
const siteSettings = canUser( 'read', {
kind: 'root',
name: 'site',
} )
? getEntityRecord( 'root', 'site' )
: undefined;
return {
pageOnFront: siteSettings?.page_on_front,
pageForPosts: siteSettings?.page_for_posts,
Expand Down
10 changes: 8 additions & 2 deletions packages/editor/src/components/post-actions/set-as-posts-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ const SetAsPostsPageModal = ( { items, closeModal } ) => {

export const useSetAsPostsPageAction = () => {
const { pageOnFront, pageForPosts } = useSelect( ( select ) => {
const { getEntityRecord } = select( coreStore );
const siteSettings = getEntityRecord( 'root', 'site' );
const { getEntityRecord, canUser } = select( coreStore );
const siteSettings = canUser( 'read', {
kind: 'root',
name: 'site',
} )
? getEntityRecord( 'root', 'site' )
: undefined;

return {
pageOnFront: siteSettings?.page_on_front,
pageForPosts: siteSettings?.page_for_posts,
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/specs/editor/blocks/navigation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ test.describe( 'Navigation block', () => {
await pageUtils.pressKeys( 'ArrowDown' );

// remove the child link
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );

const submenuBlock2 = editor.canvas.getByRole( 'document', {
name: 'Block: Submenu',
Expand Down Expand Up @@ -494,7 +494,7 @@ test.describe( 'Navigation block', () => {
await pageUtils.pressKeys( 'ArrowDown', { times: 4 } );
await navigation.checkLabelFocus( 'wordpress.org' );
// Delete the nav link
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );
// Focus moved to sibling
await navigation.checkLabelFocus( 'Dog' );
// Add a link back so we can delete the first submenu link and see if focus returns to the parent submenu item
Expand All @@ -507,15 +507,15 @@ test.describe( 'Navigation block', () => {
await pageUtils.pressKeys( 'ArrowUp', { times: 2 } );
await navigation.checkLabelFocus( 'Dog' );
// Delete the nav link
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );
await pageUtils.pressKeys( 'ArrowDown' );
// Focus moved to parent submenu item
await navigation.checkLabelFocus( 'example.com' );
// Deleting this should move focus to the sibling item
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );
await navigation.checkLabelFocus( 'Cat' );
// Deleting with no more siblings should focus the navigation block again
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );
await expect( navBlock ).toBeFocused();
// Wait until the nav block inserter is visible before we continue.
await expect( navBlockInserter ).toBeVisible();
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/various/block-deletion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ test.describe( 'Block deletion', () => {
).toBeFocused();

// Remove the current paragraph via dedicated keyboard shortcut.
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );

// Ensure the last block was removed.
await expect.poll( editor.getBlocks ).toMatchObject( [
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/various/block-locking.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ test.describe( 'Block Locking', () => {
).toBeVisible();

await paragraph.click();
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/specs/editor/various/list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,8 @@ test.describe( 'List View', () => {

// Delete remaining blocks.
// Keyboard shortcut should also work.
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );
await pageUtils.pressKeys( 'shift+Backspace' );
await expect
.poll(
listViewUtils.getBlocksWithA11yAttributes,
Expand Down Expand Up @@ -842,7 +842,7 @@ test.describe( 'List View', () => {
{ name: 'core/heading', selected: false },
] );

await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );
await expect
.poll(
listViewUtils.getBlocksWithA11yAttributes,
Expand All @@ -865,7 +865,7 @@ test.describe( 'List View', () => {
.getByRole( 'gridcell', { name: 'File' } )
.getByRole( 'link' )
.focus();
for ( const keys of [ 'Delete', 'Backspace', 'access+z' ] ) {
for ( const keys of [ 'Delete', 'Backspace', 'shift+Backspace' ] ) {
await pageUtils.pressKeys( keys );
await expect
.poll(
Expand Down Expand Up @@ -1133,7 +1133,7 @@ test.describe( 'List View', () => {
optionsForFileMenu,
'Pressing Space should also open the menu dropdown'
).toBeVisible();
await pageUtils.pressKeys( 'access+z' ); // Keyboard shortcut for Delete.
await pageUtils.pressKeys( 'shift+Backspace' ); // Keyboard shortcut for Delete.
await expect
.poll(
listViewUtils.getBlocksWithA11yAttributes,
Expand All @@ -1153,7 +1153,7 @@ test.describe( 'List View', () => {
optionsForFileMenu.getByRole( 'menuitem', { name: 'Delete' } ),
'The delete menu item should be hidden for locked blocks'
).toBeHidden();
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );
await expect
.poll(
listViewUtils.getBlocksWithA11yAttributes,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/site-editor/template-part.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ test.describe( 'Template Part', () => {
await editor.selectBlocks( siteTitle );

// Remove the default site title block.
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );

// Insert a group block with a Site Title block inside.
await editor.insertBlock( {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/widgets/editing-widgets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ test.describe( 'Widgets screen', () => {
.getByRole( 'document', { name: 'Block: Paragraph' } )
.filter( { hasText: 'Second Paragraph' } )
.focus();
await pageUtils.pressKeys( 'access+z' );
await pageUtils.pressKeys( 'shift+Backspace' );
await widgetsScreen.saveWidgets();

await expect.poll( widgetsScreen.getWidgetAreaBlocks ).toMatchObject( {
Expand Down
Loading