Skip to content

Commit

Permalink
Merge pull request #1531 from appwrite/fix-edit-attribute-modal-safari
Browse files Browse the repository at this point in the history
fix: bad modals on safari
  • Loading branch information
ArmanNik authored Nov 21, 2024
2 parents 205c242 + a2141ee commit 9f754d3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/lib/elements/forms/inputText.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { SvelteComponent, onMount } from 'svelte';
import { SvelteComponent, onMount, tick } from 'svelte';
import { FormItem, FormItemPart, Helper, Label } from '.';
import NullCheckbox from './nullCheckbox.svelte';
import TextCounter from './textCounter.svelte';
Expand Down Expand Up @@ -30,8 +30,9 @@
let error: string;
let show = false;
onMount(() => {
onMount(async () => {
if (element && autofocus) {
await tick();
element.focus();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@
}
</script>

{#if selectedAttribute}
<Modal {error} size="big" bind:show={showEdit} onSubmit={submit} icon={option?.icon}>
<svelte:fragment slot="title">
<div class="u-flex u-cross-center u-gap-8">
{option?.name}
{#if option?.type === 'relationship'}
<div class="tag eyebrow-heading-3">
<span class="text u-x-small">Beta</span>
</div>
{/if}
</div>
</svelte:fragment>
<FormList>
<Modal {error} size="big" bind:show={showEdit} onSubmit={submit} icon={option?.icon}>
<svelte:fragment slot="title">
<div class="u-flex u-cross-center u-gap-8">
{option?.name}
{#if option?.type === 'relationship'}
<div class="tag eyebrow-heading-3">
<span class="text u-x-small">Beta</span>
</div>
{/if}
</div>
</svelte:fragment>
<FormList>
{#if selectedAttribute}
{#if selectedAttribute?.type !== 'relationship'}
<InputText
id="key"
Expand All @@ -93,10 +93,10 @@
bind:data={selectedAttribute}
on:close={() => (option = null)} />
{/if}
</FormList>
<svelte:fragment slot="footer">
<Button secondary on:click={() => (showEdit = false)}>Cancel</Button>
<Button submit disabled={deepEqual(currentAttr, selectedAttribute)}>Update</Button>
</svelte:fragment>
</Modal>
{/if}
{/if}
</FormList>
<svelte:fragment slot="footer">
<Button secondary on:click={() => (showEdit = false)}>Cancel</Button>
<Button submit disabled={deepEqual(currentAttr, selectedAttribute)}>Update</Button>
</svelte:fragment>
</Modal>
5 changes: 3 additions & 2 deletions tests/unit/elements/inputText.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from 'vitest';
import { render } from '@testing-library/svelte';
import userEvent from '@testing-library/user-event';
import { InputText } from '../../../src/lib/elements/forms';
import { tick } from 'svelte';

test('shows text input', () => {
const { getByText, getByLabelText } = render(InputText, { id: 'input', label: 'input' });
Expand All @@ -24,9 +25,9 @@ test('shows text input - disabled', () => {
expect(getByLabelText('input')).toBeDisabled();
});

test('shows text input - autofocus', () => {
test('shows text input - autofocus', async () => {
const { getByLabelText } = render(InputText, { id: 'input', label: 'input', autofocus: true });

await tick();
expect(getByLabelText('input')).toHaveFocus();
});

Expand Down

0 comments on commit 9f754d3

Please sign in to comment.