Skip to content

Commit 2ea1c06

Browse files
committed
https://github.com/appirio-tech/connect-app/pull/2759#pullrequestreview-195864593
topcoder-archive/connect-app#2759 (review)
1 parent 010550b commit 2ea1c06

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

components/Dropdown/Dropdown.jsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,38 @@ class Dropdown extends React.Component {
4747
}
4848
listChild[childSelectionIndex].focus()
4949
}
50+
let searchKey = ''
51+
let timer
5052
const focusOnCharacter = (value) => {
53+
searchKey += value
54+
if (timer) {
55+
clearTimeout(timer)
56+
}
57+
timer = setTimeout(() => { searchKey = '' }, 500)
5158
const listChild = this.listRef.getElementsByTagName('li')
5259
if (listChild.length === 0) {
5360
return
5461
}
5562
const length = listChild.length
5663
for (let i = 0; i < length; i++) {
57-
const textContent = listChild[i].textContent
64+
let textContent = listChild[i].textContent
5865
if (textContent && textContent.length > 0) {
59-
const firstChar = textContent.charAt(0)
60-
if (firstChar === value || firstChar === value.toLowerCase()) {
66+
textContent = textContent.toLowerCase()
67+
const search = searchKey.toLowerCase()
68+
if (textContent.startsWith(search)) {
6169
listChild[i].focus()
6270
return true
6371
}
6472
}
6573
}
6674
return false
6775
}
76+
const onFocus = () => {
77+
this.containerRef.classList.add('focused')
78+
}
79+
const onBlur = () => {
80+
this.containerRef.classList.remove('focused')
81+
}
6882
const onKeydown = (e) => {
6983
if (!handleKeyboardNavigation) {
7084
return
@@ -100,12 +114,13 @@ class Dropdown extends React.Component {
100114
focusOnNextChild()
101115
} else if (keyCode === 38) {
102116
focusOnPreviousChild()
103-
} else if (keyCode === 13) {
117+
} else if (keyCode === 13) { // enter
104118
const listChild = this.listRef.getElementsByTagName('li')
105119
if (listChild.length === 0) {
106120
return
107121
}
108122
listChild[childSelectionIndex].click()
123+
this.handleKeyboardRef.focus()
109124
}
110125
e.preventDefault()
111126
} else {
@@ -117,13 +132,15 @@ class Dropdown extends React.Component {
117132
}
118133

119134
const setListRef = (c) => this.listRef = c
135+
const setContainerRef = (c) => this.containerRef = c
136+
const setHandleKeyboardRef = (c) => this.handleKeyboardRef = c
120137

121138
const childrenWithProps = React.Children.map(children, child =>
122139
React.cloneElement(child, {onKeyDown: onChildKeydown})
123140
)
124141
return (
125-
<div className={ddClasses} onClick={noAutoclose ? () => { } : handleClick}>
126-
{handleKeyboardNavigation && (<a tabIndex="0" onKeyDown={onKeydown} className="handle-keyboard" href="javascript:;"></a>)}
142+
<div ref={setContainerRef} className={ddClasses} onClick={noAutoclose ? () => { } : handleClick}>
143+
{handleKeyboardNavigation && (<a ref={setHandleKeyboardRef} tabIndex="0" onFocus={onFocus} onBlur={onBlur} onKeyDown={onKeydown} className="handle-keyboard" href="javascript:;"></a>)}
127144
{
128145
childrenWithProps.map((child, index) => {
129146
if (child.props.className.indexOf('dropdown-menu-header') > -1)

components/Dropdown/Dropdown.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
font-size: 12px;
3838
display: block;
3939
line-height: 26px;
40-
overflow: hidden;
41-
white-space: pre-line;
4240
}
4341
}
4442
}
@@ -81,6 +79,10 @@
8179
}
8280

8381
.dropdown-wrap {
82+
&.focused {
83+
box-shadow: 0 0 2px 0 rgba(6, 129, 255, 0.7);
84+
border: 1px solid $tc-dark-blue-100!important;
85+
}
8486
.handle-keyboard {
8587
position: absolute;
8688
width: 100%;
@@ -90,7 +92,7 @@
9092
height: 100%;
9193

9294
&:focus {
93-
outline: 5px auto -webkit-focus-ring-color;
95+
outline: none;
9496
}
9597
}
9698
}

components/Formsy/PhoneInput.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
}
7070

7171
.Dropdown {
72-
width: 200px;
72+
width: auto;
7373
margin-left: -150px;
7474
margin-top: 30px;
7575
color: black;

0 commit comments

Comments
 (0)