@@ -7,6 +7,11 @@ const React = require('react');
7
7
*/
8
8
const EDITING = 'editing' ;
9
9
10
+ /**
11
+ * The duplicate key value.
12
+ */
13
+ const DUPLICATE = 'duplicate' ;
14
+
10
15
/**
11
16
* The document key class.
12
17
*/
@@ -25,7 +30,7 @@ class EditableKey extends React.Component {
25
30
constructor ( props ) {
26
31
super ( props ) ;
27
32
this . element = props . element ;
28
- this . state = { editing : false } ;
33
+ this . state = { duplcate : false , editing : false } ;
29
34
}
30
35
31
36
/**
@@ -56,10 +61,22 @@ class EditableKey extends React.Component {
56
61
onFocus = { this . handleFocus . bind ( this ) }
57
62
onChange = { this . handleChange . bind ( this ) }
58
63
onKeyDown = { this . handleKeyDown . bind ( this ) }
59
- value = { this . element . currentKey } />
64
+ value = { this . element . currentKey }
65
+ title = { this . renderTitle ( ) } />
60
66
) ;
61
67
}
62
68
69
+ /**
70
+ * Render the title.
71
+ *
72
+ * @returns {String } The title.
73
+ */
74
+ renderTitle ( ) {
75
+ if ( this . state . duplicate ) {
76
+ return `Duplicate key: '${ this . element . currentKey } '`
77
+ }
78
+ return this . element . currentKey ;
79
+ }
63
80
/**
64
81
* When hitting a key on the last element some special things may happen.
65
82
*
@@ -79,6 +96,11 @@ class EditableKey extends React.Component {
79
96
handleChange ( evt ) {
80
97
var value = evt . target . value ;
81
98
if ( this . isEditable ( ) ) {
99
+ if ( this . element . isDuplicateKey ( value ) ) {
100
+ this . setState ( { duplicate : true } ) ;
101
+ } else if ( this . state . duplicate ) {
102
+ this . setState ( { duplicate : false } ) ;
103
+ }
82
104
this . element . rename ( value ) ;
83
105
}
84
106
}
@@ -116,7 +138,14 @@ class EditableKey extends React.Component {
116
138
* @returns {String } The key style.
117
139
*/
118
140
style ( ) {
119
- return this . state . editing ? `${ KEY_CLASS } ${ EDITING } ` : KEY_CLASS ;
141
+ var style = KEY_CLASS ;
142
+ if ( this . state . editing ) {
143
+ style = style . concat ( ` ${ EDITING } ` ) ;
144
+ }
145
+ if ( this . state . duplicate ) {
146
+ style = style . concat ( ` ${ DUPLICATE } ` ) ;
147
+ }
148
+ return style ;
120
149
}
121
150
}
122
151
0 commit comments