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

Improve email field #449

Merged
merged 16 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<div :class="['mt-field-affix', `mt-field-affix--${type}`]">
<slot />
</div>
</template>

<script setup lang="ts">
defineProps<{
type: "prefix" | "suffix";
}>();
</script>

<style scoped>
.mt-field-affix {
display: grid;
place-items: center;
padding-inline: var(--scale-size-12);
color: var(--color-text-primary-default);
font-family: var(--font-family-body);
font-size: var(--font-size-2xs);
line-height: var(--line-height-2xs);
font-weight: var(--font-weight-medium);
background: var(--color-interaction-secondary-dark);
height: 100%;
}

.mt-field-affix--suffix {
border-inline-start: 1px solid var(--color-border-primary-default);
border-top-right-radius: var(--border-radius-xs);
border-bottom-right-radius: var(--border-radius-xs);
}

.mt-field-affix--prefix {
border-inline-end: 1px solid var(--color-border-primary-default);
border-top-left-radius: var(--border-radius-xs);
border-bottom-left-radius: var(--border-radius-xs);
}
</style>
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<template>
<!-- eslint-disable-next-line vuejs-accessibility/mouse-events-have-key-events -->
<mt-icon
v-tooltip="{
message: tooltipText,
width: 220,
position: 'top',
showDelay: 300,
hideDelay: 0,
}"
class="mt-field-copyable"
name="regular-copy"
size="18"
@click="copyToClipboard"
@mouseleave="wasCopied = false"
/>
<button>
<mt-icon
v-tooltip="{
message: tooltipText,
width: 220,
position: 'top',
showDelay: 300,
hideDelay: 0,
}"
class="mt-field-copyable"
name="regular-copy"
size="18"
@click="copyToClipboard"
@mouseleave="wasCopied = false"
/>
</button>
</template>

<script lang="ts">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<mt-text
v-if="!!error"
as="span"
size="2xs"
size="xs"
color="color-text-critical-default"
class="mt-field__error"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { within, userEvent } from "@storybook/test";
import { within, userEvent, fn } from "@storybook/test";
import { expect } from "@storybook/test";

import meta, { type MtEmailFieldMeta, type MtEmailFieldStory } from "./mt-email-field.stories";
Expand All @@ -8,25 +8,6 @@ export default {
title: "Interaction Tests/Form/mt-email-field",
} as MtEmailFieldMeta;

export const TestInputValue: MtEmailFieldStory = {
name: "Should keep input value",
play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement);
const TEST_EMAIL = "[email protected]";

await userEvent.type(canvas.getByRole("textbox"), TEST_EMAIL);
await userEvent.click(canvas.getByText("hidden"));

expect((canvas.getByRole("textbox") as HTMLInputElement).value).toBe(TEST_EMAIL);

// Input to be called once for each letter

expect(args.updateModelValue).toHaveBeenCalledTimes(18);

expect(args.change).toHaveBeenCalledWith(TEST_EMAIL);
},
};

export const VisualTestPrefix: MtEmailFieldStory = {
name: "Should display prefix",
args: {
Expand Down Expand Up @@ -63,18 +44,6 @@ export const VisualTestHint: MtEmailFieldStory = {
},
};

export const TestLabel: MtEmailFieldStory = {
name: "Should display label",
args: {
label: "label",
},
play: ({ canvasElement, args }) => {
const canvas = within(canvasElement);

expect(canvas.getByText(args.label!)).toBeDefined();
},
};

export const VisualTestDisabled: MtEmailFieldStory = {
name: "Should disable",
args: {
Expand Down Expand Up @@ -114,16 +83,42 @@ export const VisualTestError: MtEmailFieldStory = {
},
};

export const VisualTestValidationError: MtEmailFieldStory = {
name: "Should validate email",
export const VisualTestSmall: MtEmailFieldStory = {
name: "Should display small",
args: {
modelValue: "admin@",
small: true,
},
play: ({ canvasElement }) => {
};

export const TestShouldCopyValue: MtEmailFieldStory = {
name: "Should copy value",
args: {
modelValue: "[email protected]",
copyable: true,
},
async play({ canvasElement }) {
window.navigator.clipboard.writeText = fn();
const canvas = within(canvasElement);

expect(
canvas.getByText("Please enter a part following '@'. 'admin@' is incomplete."),
).toBeDefined();
await userEvent.click(canvas.getByRole("button", { name: "Copy to clipboard" }));
expect(window.navigator.clipboard.writeText).toHaveBeenCalledOnce();
},
};

export const VisualTestLinkedInheritanec: MtEmailFieldStory = {
name: "Linked inheritance",
args: {
isInheritanceField: true,
isInherited: true,
modelValue: "[email protected]",
},
};

export const VisualTestUnlinkedInheritance: MtEmailFieldStory = {
name: "Unlinked inheritance",
args: {
isInheritanceField: true,
isInherited: false,
modelValue: "[email protected]",
},
};
Loading
Loading