@@ -4,7 +4,7 @@ import classnames from 'classnames';
44import debounce from 'lodash/debounce' ;
55import { setPageTitle } from '../../page/PageActions' ;
66import { removePageThunk } from '../DashboardThunks' ;
7- import { Tab , Menu , MenuItems , MenuItem , IconButton , TextInput } from '@neo4j-ndl/react' ;
7+ import { Tab , Menu , MenuItems , MenuItem , IconButton } from '@neo4j-ndl/react' ;
88import { EllipsisHorizontalIconOutline , PencilIconOutline , TrashIconOutline } from '@neo4j-ndl/react/icons' ;
99import { NeoDeletePageModal } from '../../modal/DeletePageModal' ;
1010import { useSortable } from '@dnd-kit/sortable' ;
@@ -17,12 +17,9 @@ export const DashboardHeaderPageTitle = ({ title, tabIndex, removePage, setPageT
1717 const menuOpen = Boolean ( anchorEl ) ;
1818 const [ deleteModalOpen , setDeleteModalOpen ] = React . useState ( false ) ;
1919 const [ editing , setEditing ] = React . useState ( false ) ;
20-
20+ const [ inputWidth , setInputWidth ] = React . useState ( 125 ) ;
2121 const handleMenuEditClick = ( event : MenuEditEvent ) => {
2222 event . preventDefault ( ) ;
23- if ( editing ) {
24- debouncedSetPageTitle ( tabIndex , titleText ) ;
25- }
2623 setEditing ( ! editing ) ;
2724 setAnchorEl ( null ) ;
2825 } ;
@@ -49,7 +46,7 @@ export const DashboardHeaderPageTitle = ({ title, tabIndex, removePage, setPageT
4946 transition,
5047 } ;
5148
52- const debouncedSetPageTitle = useCallback ( debounce ( setPageTitle , 250 ) , [ ] ) ;
49+ const debouncedSetPageTitle = useCallback ( debounce ( setPageTitle , 200 ) , [ ] ) ;
5350
5451 const [ titleText , setTitleText ] = React . useState ( title ) ;
5552 useEffect ( ( ) => {
@@ -69,24 +66,46 @@ export const DashboardHeaderPageTitle = ({ title, tabIndex, removePage, setPageT
6966 '(no title)'
7067 )
7168 ) : (
72- < TextInput
73- data-no-dnd = 'true'
74- autoFocus = { true }
75- value = { titleText }
76- onChange = { ( event ) => {
77- if ( disabled ) {
78- return ;
69+ < form
70+ onSubmit = { ( event ) => {
71+ if ( editing ) {
72+ handleMenuEditClick ( event ) ;
7973 }
80- setTitleText ( event . target . value ) ;
8174 } }
82- style = { {
83- textAlign : 'center' ,
84- height : '1.9rem' ,
85- } }
86- placeholder = 'Page name...'
87- />
75+ >
76+ < input
77+ data-no-dnd = 'true'
78+ autoFocus = { true }
79+ value = { titleText }
80+ className = ''
81+ onBlur = { ( event ) => {
82+ if ( editing ) {
83+ handleMenuEditClick ( event ) ;
84+ }
85+ } }
86+ onChange = { ( event ) => {
87+ const { target} = event ;
88+ target . style . width = '125px' ;
89+ setInputWidth ( target . scrollWidth ) ;
90+
91+ if ( disabled ) {
92+ return ;
93+ }
94+ setTitleText ( event . target . value ) ;
95+ debouncedSetPageTitle ( tabIndex , event . target . value ) ;
96+ } }
97+ style = { {
98+ height : '1.9rem' ,
99+ marginBottom : - 5 ,
100+ width : inputWidth ,
101+ paddingLeft : 5 ,
102+ paddingRight : 5 ,
103+ } }
104+ placeholder = 'Page name...'
105+ />
106+ </ form >
88107 ) }
89- { ! disabled && (
108+ { ! disabled && ! editing && (
90109 < >
91110 < IconButton
92111 aria-label = 'Page actions'
@@ -107,9 +126,12 @@ export const DashboardHeaderPageTitle = ({ title, tabIndex, removePage, setPageT
107126 < MenuItems >
108127 < MenuItem
109128 icon = { < PencilIconOutline /> }
110- title = { editing ? 'Stop Editing' : 'Edit name' }
129+ title = { 'Edit name' }
111130 onClick = { ( e ) => {
112131 e . stopPropagation ( ) ;
132+ if ( editing ) {
133+ debouncedSetPageTitle ( tabIndex , titleText ) ;
134+ }
113135 ! disabled && handleMenuEditClick ( e ) ;
114136 } }
115137 />
0 commit comments