Skip to content

Commit 8f97bdf

Browse files
authored
Merge pull request #4 from yuaiccc/feat/dojo-clear-btn
feat: add clear button to Dojo mode input
2 parents ddd5036 + 3bafdb6 commit 8f97bdf

2 files changed

Lines changed: 69 additions & 14 deletions

File tree

frontend/src/App.vue

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -252,19 +252,29 @@
252252
</div>
253253

254254
<div class="dojo-input-area">
255-
<input
256-
ref="dojoInputRef"
257-
v-model="dojoAnswer"
258-
type="text"
259-
class="search-input dojo-input"
260-
:class="{ 'input-correct': dojoFeedback?.isCorrect, 'input-error': dojoFeedback && !dojoFeedback.isCorrect }"
261-
placeholder="输入假名或罗马音..."
262-
@compositionstart="isComposing = true"
263-
@compositionend="isComposing = false"
264-
@keyup.enter="handleDojoEnter"
265-
:disabled="!!dojoFeedback"
266-
autocomplete="off"
267-
>
255+
<div class="dojo-input-wrapper">
256+
<input
257+
ref="dojoInputRef"
258+
v-model="dojoAnswer"
259+
type="text"
260+
class="search-input dojo-input"
261+
:class="{ 'input-correct': dojoFeedback?.isCorrect, 'input-error': dojoFeedback && !dojoFeedback.isCorrect }"
262+
placeholder="输入假名或罗马音..."
263+
@compositionstart="isComposing = true"
264+
@compositionend="isComposing = false"
265+
@keyup.enter="handleDojoEnter"
266+
:disabled="!!dojoFeedback"
267+
autocomplete="off"
268+
>
269+
<button
270+
v-if="dojoAnswer && !dojoFeedback"
271+
class="dojo-clear-btn"
272+
@click="clearDojoInput"
273+
title="清除输入"
274+
>
275+
<Icon name="x" class="icon-x" />
276+
</button>
277+
</div>
268278
<button v-if="!dojoFeedback" class="search-btn" @click="checkDojoAnswer" :disabled="!dojoAnswer.trim()">提交</button>
269279
<button v-else class="search-btn btn-next" @click="nextDojoQuestion">
270280
{{ dojoCurrentIndex < dojoQuestions.length - 1 ? '下一题' : '查看成绩' }}
@@ -484,6 +494,13 @@ const checkDojoAnswer = () => {
484494
dojoFeedback.value = { isCorrect, correctAnswer: q.answer };
485495
};
486496
497+
const clearDojoInput = () => {
498+
dojoAnswer.value = '';
499+
nextTick(() => {
500+
dojoInputRef.value?.focus();
501+
});
502+
};
503+
487504
const nextDojoQuestion = () => {
488505
if (dojoCurrentIndex.value < dojoQuestions.value.length - 1) {
489506
dojoCurrentIndex.value++;
@@ -2030,16 +2047,49 @@ ruby rt {
20302047
display: flex;
20312048
gap: 12px;
20322049
margin-bottom: 24px;
2050+
justify-content: center;
2051+
}
2052+
2053+
.dojo-input-wrapper {
2054+
position: relative;
2055+
display: flex;
2056+
align-items: center;
20332057
}
20342058
20352059
.dojo-input {
20362060
border: 2px solid var(--surface-border);
20372061
border-radius: var(--radius-md);
2038-
padding: 12px 16px;
2062+
padding: 12px 36px 12px 16px; /* Added right padding for the clear button */
20392063
font-size: 1.2em;
20402064
text-align: center;
20412065
transition: all 0.3s;
20422066
background: rgba(255, 255, 255, 0.8);
2067+
width: 100%;
2068+
}
2069+
2070+
.dojo-clear-btn {
2071+
position: absolute;
2072+
right: 10px;
2073+
background: none;
2074+
border: none;
2075+
color: #94a3b8;
2076+
cursor: pointer;
2077+
padding: 4px;
2078+
display: flex;
2079+
align-items: center;
2080+
justify-content: center;
2081+
border-radius: 50%;
2082+
transition: all 0.2s;
2083+
}
2084+
2085+
.dojo-clear-btn:hover {
2086+
color: #475569;
2087+
background: rgba(0, 0, 0, 0.05);
2088+
}
2089+
2090+
.icon-x {
2091+
width: 16px;
2092+
height: 16px;
20432093
}
20442094
20452095
.dojo-input:focus {

frontend/src/components/Icon.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
<template v-else-if="name === 'chevron'">
5959
<polyline points="8 10 12 14 16 10"></polyline>
6060
</template>
61+
62+
<template v-else-if="name === 'x'">
63+
<line x1="18" y1="6" x2="6" y2="18"></line>
64+
<line x1="6" y1="6" x2="18" y2="18"></line>
65+
</template>
6166
</svg>
6267
</template>
6368

0 commit comments

Comments
 (0)