fix(core): linked doc named input box has excessive desire to select all (#8861)
Fix issue [AF-1706](https://linear.app/affine-design/issue/AF-1706).
This commit is contained in:
@@ -21,7 +21,7 @@ export const useAutoFocus = <T extends HTMLElement = HTMLElement>(
|
|||||||
export const useAutoSelect = <T extends HTMLInputElement = HTMLInputElement>(
|
export const useAutoSelect = <T extends HTMLInputElement = HTMLInputElement>(
|
||||||
autoSelect?: boolean
|
autoSelect?: boolean
|
||||||
) => {
|
) => {
|
||||||
const ref = useAutoFocus<T>(autoSelect);
|
const ref = useRef<T | null>(null);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (ref.current && autoSelect) {
|
if (ref.current && autoSelect) {
|
||||||
|
|||||||
@@ -45,17 +45,20 @@ export const RowInput = forwardRef<HTMLInputElement, RowInputProps>(
|
|||||||
const focusRef = useAutoFocus<HTMLInputElement>(autoFocus);
|
const focusRef = useAutoFocus<HTMLInputElement>(autoFocus);
|
||||||
const selectRef = useAutoSelect<HTMLInputElement>(autoSelect);
|
const selectRef = useAutoSelect<HTMLInputElement>(autoSelect);
|
||||||
|
|
||||||
const inputRef = (el: HTMLInputElement | null) => {
|
const inputRef = useCallback(
|
||||||
focusRef.current = el;
|
(el: HTMLInputElement | null) => {
|
||||||
selectRef.current = el;
|
focusRef.current = el;
|
||||||
if (upstreamRef) {
|
selectRef.current = el;
|
||||||
if (typeof upstreamRef === 'function') {
|
if (upstreamRef) {
|
||||||
upstreamRef(el);
|
if (typeof upstreamRef === 'function') {
|
||||||
} else {
|
upstreamRef(el);
|
||||||
upstreamRef.current = el;
|
} else {
|
||||||
|
upstreamRef.current = el;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
[focusRef, selectRef, upstreamRef]
|
||||||
|
);
|
||||||
|
|
||||||
// use native blur event to get event after unmount
|
// use native blur event to get event after unmount
|
||||||
// don't use useLayoutEffect here, because the cleanup function will be called before unmount
|
// don't use useLayoutEffect here, because the cleanup function will be called before unmount
|
||||||
|
|||||||
@@ -169,10 +169,10 @@ export function patchNotificationService({
|
|||||||
<div>
|
<div>
|
||||||
<span style={{ marginBottom: 12 }}>{toReactNode(message)}</span>
|
<span style={{ marginBottom: 12 }}>{toReactNode(message)}</span>
|
||||||
<Input
|
<Input
|
||||||
|
autoSelect={true}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
defaultValue={value}
|
defaultValue={value}
|
||||||
onChange={e => (value = e)}
|
onChange={e => (value = e)}
|
||||||
ref={input => input?.select()}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -190,6 +190,7 @@ export function patchNotificationService({
|
|||||||
onCancel: () => {
|
onCancel: () => {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
},
|
},
|
||||||
|
autoFocusConfirm: false,
|
||||||
});
|
});
|
||||||
abort?.addEventListener('abort', () => {
|
abort?.addEventListener('abort', () => {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user