mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-04 16:34:52 +03:00
fix(hosts): prevent Backspace from removing tags on action buttons
This commit is contained in:
@@ -24,8 +24,8 @@ function keepFromSelect(event: MouseEvent) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
function keepActivationFromSelect(event: KeyboardEvent) {
|
||||
if (event.key === 'Enter' || event.key === ' ') event.stopPropagation();
|
||||
function keepKeyFromSelect(event: KeyboardEvent) {
|
||||
if (event.key !== 'Tab') event.stopPropagation();
|
||||
}
|
||||
|
||||
export default function HostAddressSelect({
|
||||
@@ -99,7 +99,7 @@ export default function HostAddressSelect({
|
||||
useImperativeHandle(commitEditRef, () => () => commitEdit(false));
|
||||
|
||||
function editKeyDown(event: KeyboardEvent<HTMLInputElement>) {
|
||||
if (event.key !== 'Tab') event.stopPropagation();
|
||||
keepKeyFromSelect(event);
|
||||
if (!editing || event.nativeEvent.isComposing) return;
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
@@ -179,7 +179,7 @@ export default function HostAddressSelect({
|
||||
else editButtons.current.delete(address);
|
||||
}}
|
||||
onMouseDown={keepFromSelect}
|
||||
onKeyDown={keepActivationFromSelect}
|
||||
onKeyDown={keepKeyFromSelect}
|
||||
onClick={(event) => {
|
||||
if (event.detail === 0) startEdit(address);
|
||||
}}
|
||||
@@ -193,7 +193,7 @@ export default function HostAddressSelect({
|
||||
aria-label={t('pages.hosts.addressActions.copy', { address })}
|
||||
title={t('copy')}
|
||||
onMouseDown={keepFromSelect}
|
||||
onKeyDown={keepActivationFromSelect}
|
||||
onKeyDown={keepKeyFromSelect}
|
||||
onClick={() => void copyAddress(address)}
|
||||
>
|
||||
<CopyOutlined aria-hidden />
|
||||
|
||||
@@ -40,6 +40,24 @@ describe('Host address tags', () => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it.each(['Edit', 'Copy'])(
|
||||
'keeps all addresses when Backspace is pressed on %s',
|
||||
async (action) => {
|
||||
const user = userEvent.setup();
|
||||
const save = renderHost();
|
||||
const button = screen.getByRole('button', { name: `${action} ${ipv6}` });
|
||||
button.focus();
|
||||
expect(document.activeElement).toBe(button);
|
||||
await user.keyboard('{Backspace}');
|
||||
|
||||
expect(screen.getByRole('button', { name: `Remove ${ipv6}` })).not.toBeNull();
|
||||
expect(screen.getByRole('button', { name: `Remove ${cidr}` })).not.toBeNull();
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }));
|
||||
await waitFor(() => expect(save).toHaveBeenCalledTimes(1));
|
||||
expect(save).toHaveBeenCalledWith(expect.objectContaining({ hosts: [ipv6, cidr] }));
|
||||
},
|
||||
);
|
||||
|
||||
it('pastes single and mixed-delimiter addresses and copies the exact tag text', async () => {
|
||||
vi.stubGlobal('isSecureContext', true);
|
||||
const user = userEvent.setup();
|
||||
|
||||
Reference in New Issue
Block a user