Skip to content
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

Current prop #462

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/routes/components/resourceTypeahead/resourceInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const ResourceInput: React.FC<ResourceInputProps> = ({

// apply focus to the text input
const focusTextInput = () => {
textInputGroupRef.current.querySelector('input').focus();
textInputGroupRef?.current.querySelector('input').focus();
};

const getInputGroup = () => {
Expand Down Expand Up @@ -149,9 +149,9 @@ const ResourceInput: React.FC<ResourceInputProps> = ({
// Close menu when a click occurs outside the menu or text input group
const handleOnPopperClick = event => {
if (
menuRef.current &&
!menuRef.current.contains(event.target) &&
!textInputGroupRef.current.contains(event.target)
menuRef?.current &&
!menuRef?.current.contains(event.target) &&
!textInputGroupRef?.current.contains(event.target)
) {
setIsOpen(false);
}
Expand All @@ -171,7 +171,7 @@ const ResourceInput: React.FC<ResourceInputProps> = ({
case 'ArrowUp':
case 'ArrowDown':
// Allow focus on the menu and navigate using the arrow keys
if (menuRef.current) {
if (menuRef?.current) {
const firstElement = menuRef.current.querySelector('li > button:not(:disabled)');
(firstElement as any)?.focus();
}
Expand All @@ -186,7 +186,7 @@ const ResourceInput: React.FC<ResourceInputProps> = ({
<Popper
trigger={getInputGroup()}
popper={getMenu()}
appendTo={() => textInputGroupRef.current}
appendTo={() => textInputGroupRef?.current}
isVisible={isOpen}
onDocumentClick={handleOnPopperClick}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ const OptimizationsBreakdownChart: React.FC<OptimizationsBreakdownChartProps> =
};

const handleOnResize = () => {
const { clientWidth = 0 } = containerRef.current || {};
const { clientWidth = 0 } = containerRef?.current || {};

if (clientWidth !== width) {
setWidth(clientWidth);
Expand Down Expand Up @@ -400,7 +400,7 @@ const OptimizationsBreakdownChart: React.FC<OptimizationsBreakdownChartProps> =
}, [limitData, requestData, usageData]);

useEffect(() => {
const unobserve = getResizeObserver(containerRef.current, handleOnResize);
const unobserve = getResizeObserver(containerRef?.current, handleOnResize);
return () => {
if (unobserve) {
unobserve();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/chrome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const withChrome = Component => {

useLayoutEffect(() => {
isOrgAdmin(auth).then(val => {
if (isMounted.current) {
if (isMounted?.current) {
setOrgAdmin(val);
setInitialized(true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useStateCallback = <T>(initialState: T): [T, (state: T, cb?: (_stat
useEffect(() => {
// cb.current is `undefined` on initial render,
// so we only invoke callback on state *updates*
if (cbRef.current) {
if (cbRef?.current) {
cbRef.current(state);
cbRef.current = undefined; // reset callback after execution
}
Expand Down
Loading