-
-
Notifications
You must be signed in to change notification settings - Fork 682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
web: selecting the programming language by pressing Enter key #7484
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Yash Kumar <[email protected]>
Thank you! |
@@ -236,6 +236,20 @@ type LanguageSelectorProps = { | |||
function LanguageSelector(props: LanguageSelectorProps) { | |||
const { onLanguageSelected, selectedLanguage, onClose } = props; | |||
const [languages, setLanguages] = useState(Languages); | |||
const [searchQuery, setSearchQuery] = useState(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This state is unnecessary.
@@ -258,9 +272,15 @@ function LanguageSelector(props: LanguageSelectorProps) { | |||
zIndex: 999, | |||
mt: 1 | |||
}} | |||
value={searchQuery} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary.
const query = e.target.value.toLowerCase(); | ||
setSearchQuery(query); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary.
onChange={(e) => { | ||
if (!e.target.value) return setLanguages(Languages); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change this?
const onKeyDown = useCallback( | ||
(e: React.KeyboardEvent) => { | ||
if (e.key === "Enter" && languages.length > 0) { | ||
onLanguageSelected(languages[0].filename); | ||
e.preventDefault(); | ||
} else if (e.key === "Escape") { | ||
onClose(); | ||
e.preventDefault(); | ||
} | ||
}, | ||
[languages, onLanguageSelected, onClose] | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be inline. No need for useCallback
.
Fixes: #7284
This PR adds support for selecting the programming language by pressing the Enter key.