mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-07-12 07:51:54 +08:00
feat: add destroyOnHidden property to SearchDialog modal #96
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { Modal, Input, Flex, Segmented } from 'antd';
|
import { Modal, Input, Flex, Segmented } from 'antd';
|
||||||
import { SearchOutlined } from '@ant-design/icons';
|
import { SearchOutlined } from '@ant-design/icons';
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
|
import type { InputRef } from 'antd/es/input/Input';
|
||||||
import { useI18n } from '../i18n';
|
import { useI18n } from '../i18n';
|
||||||
import { useLocation, useNavigate } from 'react-router';
|
import { useLocation, useNavigate } from 'react-router';
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ const SearchDialog: React.FC<SearchDialogProps> = ({ open, onClose }) => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const isOnFiles = location.pathname.startsWith('/files');
|
const isOnFiles = location.pathname.startsWith('/files');
|
||||||
|
const inputRef = useRef<InputRef | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return;
|
if (!open) return;
|
||||||
@@ -41,11 +43,16 @@ const SearchDialog: React.FC<SearchDialogProps> = ({ open, onClose }) => {
|
|||||||
<Modal
|
<Modal
|
||||||
open={open}
|
open={open}
|
||||||
onCancel={handleClose}
|
onCancel={handleClose}
|
||||||
|
afterOpenChange={(nextOpen) => {
|
||||||
|
if (!nextOpen) return;
|
||||||
|
window.setTimeout(() => inputRef.current?.focus(), 0);
|
||||||
|
}}
|
||||||
footer={null}
|
footer={null}
|
||||||
width={720}
|
width={720}
|
||||||
centered
|
centered
|
||||||
title={null}
|
title={null}
|
||||||
closable={false}
|
closable={false}
|
||||||
|
destroyOnHidden
|
||||||
styles={{
|
styles={{
|
||||||
body: {
|
body: {
|
||||||
padding: '12px 16px 16px',
|
padding: '12px 16px 16px',
|
||||||
@@ -81,13 +88,14 @@ const SearchDialog: React.FC<SearchDialogProps> = ({ open, onClose }) => {
|
|||||||
placeholder={t('Search files / tags / types')}
|
placeholder={t('Search files / tags / types')}
|
||||||
value={search}
|
value={search}
|
||||||
onChange={e => setSearch(e.target.value)}
|
onChange={e => setSearch(e.target.value)}
|
||||||
style={{ fontSize: 18, height: 40, flex: 1, minWidth: 240 }}
|
size="large"
|
||||||
|
style={{ flex: 1, minWidth: 240 }}
|
||||||
styles={{
|
styles={{
|
||||||
input: {
|
root: {
|
||||||
borderRadius: 20,
|
borderRadius: 20,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
autoFocus
|
ref={inputRef}
|
||||||
onPressEnter={() => {
|
onPressEnter={() => {
|
||||||
const trimmed = search.trim();
|
const trimmed = search.trim();
|
||||||
if (!trimmed) {
|
if (!trimmed) {
|
||||||
|
|||||||
Reference in New Issue
Block a user