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

検索フォームの実装 #43

Merged
merged 4 commits into from
Oct 27, 2022
Merged
Changes from 3 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
11 changes: 7 additions & 4 deletions src/components/UI/FormInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ interface Props {
modelValue: string
placeholder?: string
limit?: number
hasAtmark?: boolean
icon?: 'magnify' | 'at'
hasAnchor?: boolean
}

const props = withDefaults(defineProps<Props>(), {
placeholder: '',
limit: undefined,
hasAtmark: false,
icon: undefined,
hasAnchor: false
})
const emit = defineEmits<{
Expand All @@ -40,7 +40,9 @@ const handleInput = (event: Event) => {

<template>
<div :class="$style.container" :data-has-anchor="props.hasAnchor">
<span v-if="props.hasAtmark" :class="$style.atmark"> @ </span>
<div v-if="props.icon !== undefined" :class="$style.iconContainer">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

めっちゃ細かいんですが、typeof icon !== 'undefined' の方がいいかもしれません。

参考: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/undefined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strict modeではundefinedを上書きできないので元のままでも大丈夫ですね 🖖 ESMは常にstrict mode)

下を実行するとエラーになります

function f () {
    "use strict";
    undefined = 'po';
}
f();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます 🙇‍♂️🙇‍♂️🙇‍♂️

<icon :name="`mdi:${props.icon}`" :icon="$style.icon" />
</div>
<input
:class="$style.input"
:placeholder="props.placeholder"
Expand Down Expand Up @@ -80,7 +82,8 @@ const handleInput = (event: Event) => {
flex-grow: 1;
}

.atmark {
.iconContainer {
display: flex;
margin-right: 4px;
color: $color-secondary;
.container:focus-within & {
Expand Down