Skip to content

Commit 87ef183

Browse files
committed
fix menu blur when clicked disabled menu or scroll bar
1 parent 4ca16a3 commit 87ef183

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/scripts/DropdownMenu.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export default class DropdownMenu extends Component {
162162
render() {
163163
const {
164164
className, align = 'left', size, header, nubbinTop, hoverPopup, children, style,
165+
onFocus, onBlur,
165166
} = this.props;
166167
const dropdownMenuClassNames = classnames(
167168
className,
@@ -177,9 +178,12 @@ export default class DropdownMenu extends Component {
177178
return (
178179
<div
179180
ref={this.props.dropdownMenuRef}
180-
style={style}
181+
style={ { outline: 'none', ...style } }
181182
className={ dropdownMenuClassNames }
182183
onKeyDown={ this.onKeyDown.bind(this) }
184+
tabIndex='-1'
185+
onFocus={ onFocus }
186+
onBlur={ onBlur }
183187
>
184188
{ header ? <MenuHeader>{ header }</MenuHeader> : null }
185189
<ul className='slds-dropdown__list' role='menu'>

src/scripts/Picklist.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export default class Picklist extends Component {
212212
);
213213
}
214214

215-
renderDropdown(menuSize) {
215+
renderDropdown(menuSize, menuStyle) {
216216
const { children } = this.props;
217217
return (
218218
this.state.opened ?
@@ -221,6 +221,8 @@ export default class Picklist extends Component {
221221
size={ menuSize }
222222
onMenuItemClick={ this.onPicklistItemClick }
223223
onMenuClose={ this.onPicklistClose }
224+
style={ menuStyle }
225+
onBlur={ this.onBlur }
224226
>
225227
{ React.Children.map(children, this.renderPicklistItem) }
226228
</DropdownMenu> :
@@ -236,8 +238,8 @@ export default class Picklist extends Component {
236238

237239
render() {
238240
const id = this.props.id || this.state.id;
239-
const { label, required, error, totalCols, cols, menuSize, ...props } = this.props;
240-
const dropdown = this.renderDropdown(menuSize);
241+
const { label, required, error, totalCols, cols, menuSize, menuStyle, ...props } = this.props;
242+
const dropdown = this.renderDropdown(menuSize, menuStyle);
241243
const formElemProps = { id, label, required, error, totalCols, cols, dropdown };
242244
return (
243245
<FormElement formElementRef={ node => (this.node = node) } { ...formElemProps }>
@@ -282,6 +284,7 @@ Picklist.propTypes = {
282284
onKeyDown: PropTypes.func,
283285
onBlur: PropTypes.func,
284286
menuSize: PropTypes.string,
287+
menuStyle: PropTypes.object, // eslint-disable-line react/forbid-prop-types
285288
children: PropTypes.node,
286289
optionsSelectedText: PropTypes.string,
287290
};

stories/PicklistStories.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,25 @@ storiesOf('Picklist', module)
104104
<PicklistItem label='Picklist Item Three' value='3' />
105105
</Picklist>
106106
))
107+
.addWithInfo('Dropdown Scroll', 'Picklist control with many items', () => (
108+
<div tabIndex='-1'>
109+
<Picklist
110+
label='Picklist Label'
111+
selectedText='Select item from here'
112+
onChange={ action('change') }
113+
onValueChange={ action('valueChange') }
114+
onSelect={ action('select') }
115+
onBlur={ action('blur') }
116+
onComplete={ action('complete') }
117+
menuSize='small'
118+
menuStyle={ { maxHeight: '20rem', overflowY: 'auto' } }
119+
>
120+
{
121+
Array.from(Array(20)).map((_, i) => (
122+
<PicklistItem label={ `Picklsit Item #${i + 1}` } value={ String(i + 1) } />
123+
))
124+
}
125+
</Picklist>
126+
</div>
127+
))
107128
;

0 commit comments

Comments
 (0)