Skip to content

Commit

Permalink
UIQM-728 Keep focus on last focused element when user cancels on conf…
Browse files Browse the repository at this point in the history
…irmation modals.
  • Loading branch information
BogdanDenis committed Dec 10, 2024
1 parent d8bbd3d commit 5b04a93
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [UIQM-716](https://issues.folio.org/browse/UIQM-716) *BREAKING* Consolidate routes based on MARC type for bib and authority records to avoid page refresh after redirecting from the create page to the edit one.
* [UIQM-730](https://issues.folio.org/browse/UIQM-730) Create/Edit/Derive MARC record - Retain focus when MARC record validation rules error display. Show validation issues toasts.
* [UIQM-740](https://issues.folio.org/browse/UIQM-740) Don't show warn/fail error toasts when there are no warns/fails.
* [UIQM-728](https://issues.folio.org/browse/UIQM-728) Keep focus on last focused element when user cancels on confirmation modals.

## [9.0.2] (IN PROGRESS)

Expand Down
13 changes: 11 additions & 2 deletions src/QuickMarcEditor/QuickMarcEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ const QuickMarcEditor = ({

const cancelUpdateLinks = () => {
setIsUpdate0101xxfieldsAuthRecModalOpen(false);
setTimeout(() => {
focusLastFocusedInput();
});
};

const confirmUpdateLinks = async (e) => {
Expand All @@ -461,17 +464,23 @@ const QuickMarcEditor = ({
};

const cancelDeleteFields = () => {
setIsDeleteModalOpened(false);

if (deletedRecords.length) {
restoreDeletedRecords();
} else {
reset();
}

setIsDeleteModalOpened(false);
setTimeout(() => {
focusLastFocusedInput();
});
};

const cancelRemoveLinking = () => {
setIsUnlinkRecordsModalOpen(false);
setTimeout(() => {
focusLastFocusedInput();
});
};

const confirmRemoveLinking = () => {
Expand Down
23 changes: 20 additions & 3 deletions src/QuickMarcEditor/QuickMarcEditor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ const initialValues = {
indicators: ['2', '\\'],
id: 'test-id-1',
},
{
tag: '999',
content: '',
indicators: ['f', 'f'],
id: '999',
},
],
};

Expand Down Expand Up @@ -764,7 +770,7 @@ describe('Given QuickMarcEditor', () => {
});

describe('when click Cancel', () => {
it('should hide ConfirmationModal and restore deleted fields', async () => {
beforeEach(async () => {
const {
getAllByRole,
getByText,
Expand All @@ -780,10 +786,21 @@ describe('Given QuickMarcEditor', () => {

await act(async () => fireEvent.click(getByText('stripes-acq-components.FormFooter.save')));
await fireEvent.click(getByText('Cancel'));
});

it('should hide ConfirmationModal and restore deleted fields', async () => {
await waitFor(() => {
expect(queryByText('Confirmation modal')).toBeNull();
expect(getByText('$a Test title')).toBeDefined();
expect(screen.queryByText('Confirmation modal')).toBeNull();
expect(screen.getByText('$a Test title')).toBeDefined();
});
});

it('should keep focus on the last focused element', async () => {
const moveUpButtons = screen.getAllByRole('button', { name: 'ui-quick-marc.record.moveUpRow' });

await waitFor(() => {
expect(screen.getByText('$a Test title')).toBeDefined();
expect(moveUpButtons[moveUpButtons.length - 1]).toHaveFocus();
});
});
});
Expand Down

0 comments on commit 5b04a93

Please sign in to comment.