Skip to content

Commit

Permalink
feat: implement react-focus-on package for command input
Browse files Browse the repository at this point in the history
  • Loading branch information
borcherd committed Dec 4, 2024
1 parent 5a17d7a commit fcfb485
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/mrgn-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"recharts": "^2.13.0",
"superstruct": "^1.0.4",
"vaul": "^0.9.0",
"zustand": "^4.4.1"
"zustand": "^4.4.1",
"react-focus-on": "^3.9.4"
},
"devDependencies": {
"@mrgnlabs/eslint-config-custom": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";

import { FocusOn } from "react-focus-on";
import { IconX } from "@tabler/icons-react";

import { ExtendedBankInfo } from "@mrgnlabs/marginfi-v2-ui-state";

import { Command, CommandInput, CommandList } from "~/components/ui/command";
Expand All @@ -18,7 +17,7 @@ export const BankListCommand = ({ selectedBank, onSetSearchQuery, onClose, child
const isMobile = useIsMobile();

return (
<>
<FocusOn onEscapeKey={onClose} onClickOutside={onClose} autoFocus={!isMobile}>
<Command
className="bg-mfi-action-box-background relative"
shouldFilter={false}
Expand All @@ -28,14 +27,17 @@ export const BankListCommand = ({ selectedBank, onSetSearchQuery, onClose, child
placeholder="Search token..."
wrapperClassName="fixed mx-2 lg:mx-0 bg-mfi-action-box-background w-[calc(100%-30px)] px-4 lg:pl-3 border rounded-lg border-border z-40 flex justify-between"
className="h-12"
autoFocus={false}
onValueChange={(value) => onSetSearchQuery(value)}
/>
<button onClick={() => onClose()} className={cn("fixed z-50", isMobile ? "top-9 right-4" : "top-8 right-6")}>
<button
onClick={onClose}
className={cn("fixed z-50", isMobile ? "top-9 right-4" : "top-8 right-6")}
aria-label="Close"
>
<IconX size={18} className="opacity-50" />
</button>
<CommandList className="overflow-auto mt-[60px]">{children}</CommandList>
</Command>
</>
</FocusOn>
);
};
62 changes: 59 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,13 @@
dependencies:
regenerator-runtime "^0.14.0"

"@babel/runtime@^7.12.13":
version "7.26.0"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.26.0.tgz#8600c2f595f277c60815256418b85356a65173c1"
integrity sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==
dependencies:
regenerator-runtime "^0.14.0"

"@babel/runtime@^7.24.8":
version "7.24.8"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.8.tgz#5d958c3827b13cc6d05e038c07fb2e5e3420d82e"
Expand Down Expand Up @@ -12937,7 +12944,7 @@ argparse@^2.0.1:
resolved "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==

aria-hidden@^1.1.1:
aria-hidden@^1.1.1, aria-hidden@^1.2.2:
version "1.2.4"
resolved "https://registry.npmjs.org/aria-hidden/-/aria-hidden-1.2.4.tgz"
integrity sha512-y+CcFFwelSXpLZk/7fMB2mUbGtX9lKycf1MWJ7CaTIERyitVlyQx6C+sxcROU2BAJ24OiZyK+8wj2i8AlBoS3A==
Expand Down Expand Up @@ -18077,6 +18084,13 @@ [email protected]:
resolved "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz"
integrity sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==

focus-lock@^1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/focus-lock/-/focus-lock-1.3.5.tgz#aa644576e5ec47d227b57eb14e1efb2abf33914c"
integrity sha512-QFaHbhv9WPUeLYBDe/PAuLKJ4Dd9OPvKs9xZBr3yLXnUrDNaVXKu2baDBXe3naPY30hgHYSsf2JW4jzas2mDEQ==
dependencies:
tslib "^2.0.3"

follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.14.7, follow-redirects@^1.14.8, follow-redirects@^1.14.9, follow-redirects@^1.15.6:
version "1.15.6"
resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz"
Expand Down Expand Up @@ -25328,6 +25342,13 @@ react-apple-signin-auth@^1.1.0:
resolved "https://registry.npmjs.org/react-apple-signin-auth/-/react-apple-signin-auth-1.1.0.tgz"
integrity sha512-cEFj5kVBa0R7K2Ah/F0kVtttVX19YZ0Fm6tSAICxEj9SmP6kwYHUysZ8N558cHHG09/cK+NTZ9pUxGVNXlG2Lg==

react-clientside-effect@^1.2.6:
version "1.2.6"
resolved "https://registry.yarnpkg.com/react-clientside-effect/-/react-clientside-effect-1.2.6.tgz#29f9b14e944a376b03fb650eed2a754dd128ea3a"
integrity sha512-XGGGRQAKY+q25Lz9a/4EPqom7WRjz3z9R2k4jhVKA/puQFH/5Nt27vFZYql4m4NVNdUvX8PS3O7r/Zzm7cjUlg==
dependencies:
"@babel/runtime" "^7.12.13"

react-confetti@^6.1.0:
version "6.1.0"
resolved "https://registry.npmjs.org/react-confetti/-/react-confetti-6.1.0.tgz"
Expand Down Expand Up @@ -25388,6 +25409,30 @@ [email protected]:
resolved "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.11.tgz"
integrity sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg==

react-focus-lock@^2.11.3:
version "2.13.2"
resolved "https://registry.yarnpkg.com/react-focus-lock/-/react-focus-lock-2.13.2.tgz#e1addac2f8b9550bc0581f3c416755ba0f81f5ef"
integrity sha512-T/7bsofxYqnod2xadvuwjGKHOoL5GH7/EIPI5UyEvaU/c2CcphvGI371opFtuY/SYdbMsNiuF4HsHQ50nA/TKQ==
dependencies:
"@babel/runtime" "^7.0.0"
focus-lock "^1.3.5"
prop-types "^15.6.2"
react-clientside-effect "^1.2.6"
use-callback-ref "^1.3.2"
use-sidecar "^1.1.2"

react-focus-on@^3.9.4:
version "3.9.4"
resolved "https://registry.yarnpkg.com/react-focus-on/-/react-focus-on-3.9.4.tgz#0b6c13273d86243c330d1aa53af39290f543da7b"
integrity sha512-NFKmeH6++wu8e7LJcbwV8TTd4L5w/U5LMXTMOdUcXhCcZ7F5VOvgeTHd4XN1PD7TNmdvldDu/ENROOykUQ4yQg==
dependencies:
aria-hidden "^1.2.2"
react-focus-lock "^2.11.3"
react-remove-scroll "^2.6.0"
react-style-singleton "^2.2.1"
tslib "^2.3.1"
use-sidecar "^1.1.2"

react-freeze@^1.0.0:
version "1.0.4"
resolved "https://registry.npmjs.org/react-freeze/-/react-freeze-1.0.4.tgz"
Expand Down Expand Up @@ -25650,7 +25695,7 @@ react-refresh@^0.4.0:
resolved "https://registry.npmjs.org/react-refresh/-/react-refresh-0.4.3.tgz"
integrity sha512-Hwln1VNuGl/6bVwnd0Xdn1e84gT/8T9aYNL+HAKDArLCS7LWjwr7StE30IEYbIkx0Vi3vs+coQxe+SQDbGbbpA==

react-remove-scroll-bar@^2.3.3, react-remove-scroll-bar@^2.3.4:
react-remove-scroll-bar@^2.3.3, react-remove-scroll-bar@^2.3.4, react-remove-scroll-bar@^2.3.6:
version "2.3.6"
resolved "https://registry.npmjs.org/react-remove-scroll-bar/-/react-remove-scroll-bar-2.3.6.tgz"
integrity sha512-DtSYaao4mBmX+HDo5YWYdBWQwYIQQshUV/dVxFxK+KM26Wjwp1gZ6rv6OC3oujI6Bfu6Xyg3TwK533AQutsn/g==
Expand Down Expand Up @@ -25680,6 +25725,17 @@ [email protected]:
use-callback-ref "^1.3.0"
use-sidecar "^1.1.2"

react-remove-scroll@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/react-remove-scroll/-/react-remove-scroll-2.6.0.tgz#fb03a0845d7768a4f1519a99fdb84983b793dc07"
integrity sha512-I2U4JVEsQenxDAKaVa3VZ/JeJZe0/2DxPWL8Tj8yLKctQJQiZM52pn/GWFpSp8dftjM3pSAHVJZscAnC/y+ySQ==
dependencies:
react-remove-scroll-bar "^2.3.6"
react-style-singleton "^2.2.1"
tslib "^2.1.0"
use-callback-ref "^1.3.0"
use-sidecar "^1.1.2"

react-responsive@^9.0.2:
version "9.0.2"
resolved "https://registry.npmjs.org/react-responsive/-/react-responsive-9.0.2.tgz"
Expand Down Expand Up @@ -29121,7 +29177,7 @@ usb@^2.11.0:
node-addon-api "^8.0.0"
node-gyp-build "^4.5.0"

use-callback-ref@^1.3.0:
use-callback-ref@^1.3.0, use-callback-ref@^1.3.2:
version "1.3.2"
resolved "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.3.2.tgz"
integrity sha512-elOQwe6Q8gqZgDA8mrh44qRTQqpIHDcZ3hXTLjBe1i4ph8XpNJnO+aQf3NaG+lriLopI4HMx9VjQLfPQ6vhnoA==
Expand Down

0 comments on commit fcfb485

Please sign in to comment.