Skip to content
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 @@ -12,7 +12,7 @@
*/

import { FieldProps } from '@rjsf/utils';
import { render, screen } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';
import { ReactElement } from 'react';
import CoreEnumMultiSelectField, {
ALL_VALUE,
Expand Down Expand Up @@ -74,6 +74,15 @@ describe('CoreEnumMultiSelectField', () => {
expect(screen.queryByText('Topic')).not.toBeInTheDocument();
});

it('reports focus to the form so its doc panel can follow the field', () => {
const handleFocus = jest.fn();
renderField({ formData: [], formContext: { handleFocus } });

act(() => screen.getByRole('combobox').focus());

expect(handleFocus).toHaveBeenCalledWith('root/entities');
});

it('is disabled when read-only', () => {
renderField({ formData: [], readonly: true });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const getNextEnumSelection = (
const CoreEnumMultiSelectField = ({
schema,
formData,
formContext,
idSchema,
name,
disabled,
Expand Down Expand Up @@ -138,6 +139,8 @@ const CoreEnumMultiSelectField = ({
label={schema.title ?? getFormDisplayLabel(name)}
placeholder={t('label.select-field', { field: schema.title ?? name })}
selectedItems={selected}
// Lets a form's doc panel follow this field, as CoreArrayField does.
onFocus={() => formContext?.handleFocus?.(idSchema.$id)}
onItemCleared={handleCleared}
onItemInserted={handleInserted}>
{(item) => (
Expand Down
Loading