1- import { AutocompleteCloseReason , Grid , Typography } from "@mui/material" ;
1+ import { AutocompleteCloseReason , Grid2 , Typography } from "@mui/material" ;
22import {
3- CSSProperties ,
43 ReactElement ,
54 RefObject ,
65 useCallback ,
@@ -22,7 +21,6 @@ import VernDialog from "components/DataEntry/DataEntryTable/NewEntry/VernDialog"
2221import { focusInput } from "components/DataEntry/utilities" ;
2322import PronunciationsFrontend from "components/Pronunciations/PronunciationsFrontend" ;
2423import { type StoreState } from "rootRedux/types" ;
25- import theme from "types/theme" ;
2624import { FileWithSpeakerId } from "types/word" ;
2725
2826export enum NewEntryId {
@@ -38,11 +36,6 @@ export enum FocusTarget {
3836 Vernacular ,
3937}
4038
41- const gridItemStyle = ( spacing : number ) : CSSProperties => ( {
42- paddingInline : theme . spacing ( spacing ) ,
43- position : "relative" ,
44- } ) ;
45-
4639interface NewEntryProps {
4740 analysisLang : WritingSystem ;
4841 vernacularLang : WritingSystem ;
@@ -224,44 +217,48 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
224217 } ;
225218
226219 return (
227- < Grid alignItems = "center" container id = { NewEntryId . GridNewEntry } >
228- < Grid container item xs = { 4 } style = { gridItemStyle ( 2 ) } >
229- < Grid item xs = { 12 } >
230- < VernWithSuggestions
231- isNew
232- vernacular = { newVern }
233- vernInput = { vernInput }
234- updateVernField = { ( newValue : string , openDialog ?: boolean ) =>
235- updateVernField ( newValue , openDialog )
220+ < Grid2
221+ alignItems = "center"
222+ container
223+ id = { NewEntryId . GridNewEntry }
224+ spacing = { 1 }
225+ >
226+ < Grid2 size = { 4 } >
227+ < VernWithSuggestions
228+ isNew
229+ vernacular = { newVern }
230+ vernInput = { vernInput }
231+ updateVernField = { ( newValue : string , openDialog ?: boolean ) =>
232+ updateVernField ( newValue , openDialog )
233+ }
234+ onBlur = { ( ) => setVernOpen ( true ) }
235+ onClose = { ( _ , reason : AutocompleteCloseReason ) => {
236+ // Handle if the user fully types an identical vernacular to a suggestion
237+ // and selects it from the Autocomplete. This should open the dialog.
238+ if ( reason === "selectOption" ) {
239+ // User pressed Enter or Left Click on an item.
240+ setVernOpen ( true ) ;
236241 }
237- onBlur = { ( ) => setVernOpen ( true ) }
238- onClose = { ( _ , reason : AutocompleteCloseReason ) => {
239- // Handle if the user fully types an identical vernacular to a suggestion
240- // and selects it from the Autocomplete. This should open the dialog.
241- if ( reason === "selectOption" ) {
242- // User pressed Enter or Left Click on an item.
243- setVernOpen ( true ) ;
244- }
245- } }
246- onFocus = { handleOnVernFocus }
247- suggestedVerns = { suggestedVerns }
248- // To prevent unintentional no-gloss or wrong-gloss submissions
249- // and to simplify interactions with Autocomplete and with the dialogs:
250- // if Enter is pressed from the vern field, move focus to gloss field.
251- handleEnter = { ( ) => focus ( FocusTarget . Gloss ) }
252- vernacularLang = { vernacularLang }
253- textFieldId = { NewEntryId . TextFieldVern }
254- onUpdate = { ( ) => conditionalFocus ( FocusTarget . Vernacular ) }
255- />
256- < VernDialog
257- open = { vernOpen && ! ! suggestedDups . length && ! selectedDup }
258- handleClose = { handleCloseVernDialog }
259- vernacularWords = { suggestedDups }
260- analysisLang = { analysisLang . bcp47 }
261- />
262- </ Grid >
263- </ Grid >
264- < Grid item xs = { 4 } style = { gridItemStyle ( 1 ) } >
242+ } }
243+ onFocus = { handleOnVernFocus }
244+ suggestedVerns = { suggestedVerns }
245+ // To prevent unintentional no-gloss or wrong-gloss submissions
246+ // and to simplify interactions with Autocomplete and with the dialogs:
247+ // if Enter is pressed from the vern field, move focus to gloss field.
248+ handleEnter = { ( ) => focus ( FocusTarget . Gloss ) }
249+ vernacularLang = { vernacularLang }
250+ textFieldId = { NewEntryId . TextFieldVern }
251+ onUpdate = { ( ) => conditionalFocus ( FocusTarget . Vernacular ) }
252+ />
253+ < VernDialog
254+ open = { vernOpen && ! ! suggestedDups . length && ! selectedDup }
255+ handleClose = { handleCloseVernDialog }
256+ vernacularWords = { suggestedDups }
257+ analysisLang = { analysisLang . bcp47 }
258+ />
259+ </ Grid2 >
260+
261+ < Grid2 size = { 4 } >
265262 < GlossWithSuggestions
266263 isNew
267264 gloss = { newGloss }
@@ -272,8 +269,9 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
272269 textFieldId = { NewEntryId . TextFieldGloss }
273270 onUpdate = { ( ) => conditionalFocus ( FocusTarget . Gloss ) }
274271 />
275- </ Grid >
276- < Grid item xs = { 1 } style = { gridItemStyle ( 1 ) } >
272+ </ Grid2 >
273+
274+ < Grid2 size = { 1 } >
277275 { ! selectedDup ?. id && (
278276 // note is not available if user selected to modify an existing entry
279277 < NoteButton
@@ -282,32 +280,35 @@ export default function NewEntry(props: NewEntryProps): ReactElement {
282280 updateNote = { setNewNote }
283281 />
284282 ) }
285- </ Grid >
286- < Grid item xs = { 2 } style = { gridItemStyle ( 1 ) } >
283+ </ Grid2 >
284+
285+ < Grid2 size = { 2 } >
287286 < PronunciationsFrontend
288287 audio = { newAudio }
289288 deleteAudio = { delNewAudio }
290289 replaceAudio = { repNewAudio }
291290 uploadAudio = { addNewAudio }
292291 onClick = { ( ) => focus ( FocusTarget . Gloss ) }
293292 />
294- </ Grid >
295- < Grid item xs = { 1 } style = { gridItemStyle ( 1 ) } >
293+ </ Grid2 >
294+
295+ < Grid2 size = { 1 } >
296296 < DeleteEntry
297297 buttonId = { NewEntryId . ButtonDelete }
298298 removeEntry = { ( ) => resetState ( ) }
299299 />
300- </ Grid >
300+ </ Grid2 >
301+
301302 < EnterGrid />
302- </ Grid >
303+ </ Grid2 >
303304 ) ;
304305}
305306
306307function EnterGrid ( ) : ReactElement {
307308 const { t } = useTranslation ( ) ;
308309 return (
309- < Grid item xs = { 12 } style = { { paddingInlineStart : theme . spacing ( 2 ) } } >
310+ < Grid2 size = { 12 } sx = { { paddingInlineStart : 1 } } >
310311 < Typography variant = "body2" > { t ( "addWords.pressEnter" ) } </ Typography >
311- </ Grid >
312+ </ Grid2 >
312313 ) ;
313314}
0 commit comments