Skip to content

Commit

Permalink
🚸 fix: 修正回车无法打开页面的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 16, 2021
1 parent c72121b commit 7f42d62
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/contentScripts/searchBar/app/SearchResult/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const SearchResult: FC = () => {
handleResultIndex,
isFocusOnResult,
resultRef,
openPage,
} = useKeyboardResult();

return (
Expand All @@ -32,7 +33,7 @@ const SearchResult: FC = () => {
className={styles.skeleton}
>
{result?.map((item, index) => {
const { title, info, id, url, target, type } = item;
const { title, info, id, target, type } = item;

return (
<div
Expand All @@ -42,7 +43,7 @@ const SearchResult: FC = () => {
[styles.selected]: isFocusOnResult && resultIndex === index,
})}
onClick={() => {
window.open(url);
openPage();
}}
onMouseEnter={() => {
handleResultIndex(index);
Expand Down
7 changes: 1 addition & 6 deletions src/contentScripts/searchBar/app/SearchResult/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,12 @@
.selected {
background: @item-hover-bg;
}
[theme='light'] {
.row:hover {
//.selected;
}
}

[theme='dark'] {
.desc {
.dark-mode-text-color-second;
}
.row:hover {
.selected {
background: @dark-mode-background-light-hover;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ export const useKeyboardResult = () => {
}
};

const openPage = () => {
window.open(result[resultIndex].url);
};
/**
* 按 上下键切换选中的 result
* @param index
* @param back
*/
const switchResultIndex = (back?: boolean) => {
Expand Down Expand Up @@ -97,6 +99,9 @@ export const useKeyboardResult = () => {
case 'Escape':
focusOnInput();
break;
case 'Enter':
openPage();
break;
default:
}
};
Expand All @@ -113,5 +118,6 @@ export const useKeyboardResult = () => {
resultIndex,
handleResultIndex,
isFocusOnResult: focusKey === 'result',
openPage,
};
};

0 comments on commit 7f42d62

Please sign in to comment.