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

fix(ui): correctly show blocks after blocksDrawer close #10847

Merged
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
4 changes: 2 additions & 2 deletions packages/ui/src/fields/Blocks/BlocksDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export const BlocksDrawer: React.FC<Props> = (props) => {
const { i18n, t } = useTranslation()

useEffect(() => {
if (!isModalOpen) {
if (!isModalOpen(drawerSlug)) {
setSearchTerm('')
}
}, [isModalOpen])
}, [isModalOpen, drawerSlug])

useEffect(() => {
const searchTermToUse = searchTerm.toLowerCase()
Expand Down
27 changes: 27 additions & 0 deletions test/fields/collections/Blocks/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,33 @@ describe('Block fields', () => {
)
})

test('should reset search state in blocks drawer on re-open', async () => {
await page.goto(url.create)
const addButton = page.locator('#field-blocks > .blocks-field__drawer-toggler')
await expect(addButton).toContainText('Add Block')
await addButton.click()

const blocksDrawer = page.locator('[id^=drawer_1_blocks-drawer-]')
await expect(blocksDrawer).toBeVisible()

const searchInput = page.locator('.block-search__input')
await searchInput.fill('Number')

// select the first block in the drawer
const firstBlockSelector = blocksDrawer
.locator('.blocks-drawer__blocks .blocks-drawer__block')
.first()

await expect(firstBlockSelector).toContainText('Number')

await page.locator('.drawer__header__close').click()
await addButton.click()

await expect(blocksDrawer).toBeVisible()
await expect(searchInput).toHaveValue('')
await expect(firstBlockSelector).toContainText('Content')
})

test('should open blocks drawer from block row and add below', async () => {
await page.goto(url.create)
const firstRow = page.locator('#field-blocks #blocks-row-0')
Expand Down