Skip to content
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
9 changes: 8 additions & 1 deletion web/pgadmin/static/js/SchemaView/DataGridView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { DepListenerContext } from './DepListener';
import { useIsMounted } from '../custom_hooks';
import { InputText } from '../components/FormComponents';
import { usePgAdmin } from '../BrowserComponent';
import { requestAnimationAndFocus } from '../utils';

const useStyles = makeStyles((theme)=>({
grid: {
Expand Down Expand Up @@ -221,6 +222,10 @@ function DataTableRow({index, row, totalRows, isResizing, isHovered, schema, sch
}
});
});

// Try autofocus on newly added row.
requestAnimationAndFocus(rowRef.current?.querySelector('input'));

return ()=>{
/* Cleanup the listeners when unmounting */
depListener?.removeDepListener(accessPath);
Expand Down Expand Up @@ -656,7 +661,9 @@ export default function DataGridView({
{props.canEdit && row.isExpanded &&
<FormView value={row.original} viewHelperProps={viewHelperProps} dataDispatch={dataDispatch}
schema={schemaRef.current} accessPath={accessPath.concat([row.index])} isNested={true} className={classes.expandedForm}
isDataGridForm={true}/>
isDataGridForm={true} firstEleRef={(ele)=>{
requestAnimationAndFocus(ele);
}}/>
}
</React.Fragment>;
})}
Expand Down
6 changes: 5 additions & 1 deletion web/pgadmin/static/js/SchemaView/FormView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ export default function FormView({
let currentControl = <MappedFormControl
inputRef={(ele)=>{
if(firstEleRef && firstEleID.current === field.id) {
firstEleRef.current = ele;
if(typeof firstEleRef == 'function') {
firstEleRef(ele);
} else {
firstEleRef.current = ele;
}
}
}}
state={value}
Expand Down
20 changes: 20 additions & 0 deletions web/pgadmin/static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,23 @@ export function gettextForTranslation(translations, ...replaceArgs) {
return rawTranslation;
}
}

// https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame
const requestAnimationFrame =
window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame;

const cancelAnimationFrame =
window.cancelAnimationFrame || window.mozCancelAnimationFrame;

/* Usefull in focussing an element after it appears on the screen */
export function requestAnimationAndFocus(ele) {
if(!ele) return;

const animateId = requestAnimationFrame(()=>{
ele?.focus?.();
cancelAnimationFrame(animateId);
});
}