-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Convert Media Inserter to Tabs Pattern #60970
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
36d5f9b
Start on converting media to tabs pattern
jeryj e1a980e
Convert block patterns tablist into catebory tabs component
jeryj 9a7692a
Implement CategoryTabs for media tab and tab panel
jeryj e8317a5
Remove MediaCategoryDialog
jeryj 0ba3121
Fix e2e test selectors for tab element
jeryj 5c028eb
Fix formatting of failing e2e test
jeryj 6873975
Remove bottom margin from media panel search
jeryj bda3f20
Stick all pattern all media buttons to bottom of inserter sidebar
jeryj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/block-editor/src/components/inserter/category-tabs/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { isRTL } from '@wordpress/i18n'; | ||
import { | ||
__experimentalHStack as HStack, | ||
FlexBlock, | ||
privateApis as componentsPrivateApis, | ||
} from '@wordpress/components'; | ||
import { Icon, chevronRight, chevronLeft } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../../lock-unlock'; | ||
|
||
const { Tabs } = unlock( componentsPrivateApis ); | ||
|
||
function CategoryTabs( { | ||
categories, | ||
selectedCategory, | ||
onSelectCategory, | ||
children, | ||
} ) { | ||
return ( | ||
<Tabs | ||
className="block-editor-inserter__category-tabs" | ||
selectOnMove={ false } | ||
selectedTabId={ selectedCategory ? selectedCategory.name : null } | ||
orientation={ 'vertical' } | ||
onSelect={ ( categoryId ) => { | ||
// Pass the full category object | ||
onSelectCategory( | ||
categories.find( | ||
( category ) => category.name === categoryId | ||
) | ||
); | ||
} } | ||
> | ||
<Tabs.TabList className="block-editor-inserter__category-tablist"> | ||
{ categories.map( ( category ) => ( | ||
<Tabs.Tab | ||
key={ category.name } | ||
tabId={ category.name } | ||
className="block-editor-inserter__category-tab" | ||
aria-label={ category.label } | ||
aria-current={ | ||
category === selectedCategory ? 'true' : undefined | ||
} | ||
> | ||
<HStack> | ||
<FlexBlock>{ category.label }</FlexBlock> | ||
<Icon | ||
icon={ isRTL() ? chevronLeft : chevronRight } | ||
/> | ||
</HStack> | ||
</Tabs.Tab> | ||
) ) } | ||
</Tabs.TabList> | ||
{ categories.map( ( category ) => ( | ||
<Tabs.TabPanel | ||
key={ category.name } | ||
tabId={ category.name } | ||
focusable={ false } | ||
className="block-editor-inserter__category-panel" | ||
> | ||
{ children } | ||
</Tabs.TabPanel> | ||
) ) } | ||
</Tabs> | ||
); | ||
} | ||
|
||
export default CategoryTabs; |
2 changes: 1 addition & 1 deletion
2
packages/block-editor/src/components/inserter/media-tab/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { default as MediaTab } from './media-tab'; | ||
export { MediaCategoryDialog } from './media-panel'; | ||
export { MediaCategoryPanel } from './media-panel'; | ||
export { useMediaCategories } from './hooks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRef, useEffect } from '@wordpress/element'; | ||
import { Spinner, SearchControl } from '@wordpress/components'; | ||
import { focus } from '@wordpress/dom'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useDebouncedInput } from '@wordpress/compose'; | ||
|
||
|
@@ -16,26 +14,6 @@ import InserterNoResults from '../no-results'; | |
|
||
const INITIAL_MEDIA_ITEMS_PER_PAGE = 10; | ||
|
||
export function MediaCategoryDialog( { rootClientId, onInsert, category } ) { | ||
const container = useRef(); | ||
useEffect( () => { | ||
const timeout = setTimeout( () => { | ||
const [ firstTabbable ] = focus.tabbable.find( container.current ); | ||
firstTabbable?.focus(); | ||
} ); | ||
return () => clearTimeout( timeout ); | ||
}, [ category ] ); | ||
Comment on lines
-20
to
-27
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. Auto-focusing from a tab selection isn't a normal flow, so we can remove this interaction which simplifies things. |
||
return ( | ||
<div ref={ container } className="block-editor-inserter__media-dialog"> | ||
<MediaCategoryPanel | ||
rootClientId={ rootClientId } | ||
onInsert={ onInsert } | ||
category={ category } | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export function MediaCategoryPanel( { rootClientId, onInsert, category } ) { | ||
const [ search, setSearch, debouncedSearch ] = useDebouncedInput(); | ||
const { mediaList, isLoading } = useMediaResults( category, { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since both components share so much code, it made sense to refactor this.