Skip to content

Commit 42f137a

Browse files
committed
add disabled property handling
1 parent eb40012 commit 42f137a

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/scripts/Lookup.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ export class LookupSearch extends Component {
100100
'.slds-lookup[data-scope="multi"] .slds-box--border',
101101
'{ background-color: white; }',
102102
],
103+
[
104+
'.slds-lookup[data-scope="multi"] .slds-box--border.react-slds-box-disabled',
105+
'{ background-color: #e0e5ee; border-color: #a8b7c7; cursor: not-allowed; }',
106+
],
103107
[
104108
'.slds-lookup[data-scope="multi"] .slds-box--border .slds-input--bare',
105109
'{ height: 2.15rem; width: 100%; }',
@@ -211,8 +215,8 @@ export class LookupSearch extends Component {
211215
/>
212216
<span
213217
tabIndex={ -1 }
214-
style={ { cursor: 'pointer' } }
215-
onClick={ this.onLookupIconClick }
218+
style={ props.disabled ? undefined : { cursor: 'pointer' } }
219+
onClick={ props.disabled ? undefined : this.onLookupIconClick }
216220
>
217221
<Icon
218222
icon='search'
@@ -223,7 +227,7 @@ export class LookupSearch extends Component {
223227
);
224228
}
225229

226-
renderScopeSelector(scopes, target) {
230+
renderScopeSelector({ scopes, target, disabled }) {
227231
let targetScope = scopes[0] || {};
228232
for (const scope of scopes) {
229233
if (scope.value === target) {
@@ -242,6 +246,7 @@ export class LookupSearch extends Component {
242246
<div className={ selectorClassNames }>
243247
<DropdownButton
244248
label={ icon }
249+
disabled={ disabled }
245250
onClick={ this.onScopeMenuClick }
246251
onMenuItemClick={ this.onMenuItemClick }
247252
onBlur={ this.onInputBlur }
@@ -253,19 +258,20 @@ export class LookupSearch extends Component {
253258
}
254259

255260
render() {
256-
const { scopes, hidden, targetScope, ...props } = this.props;
261+
const { scopes, hidden, disabled, targetScope, ...props } = this.props;
257262
if (scopes) {
258263
const lookupSearchClassNames = classnames(
259264
'slds-grid',
260265
'slds-form-element__control',
261266
'slds-box--border',
267+
{ 'react-slds-box-disabled': disabled },
262268
{ 'slds-hide': hidden }
263269
);
264270
const styles = { WebkitFlexWrap: 'nowrap', msFlexWrap: 'nowrap', flexWrap: 'nowrap' };
265271
return (
266272
<div ref={ this.handleLookupSearchRef } className={ lookupSearchClassNames } style={ styles }>
267-
{ this.renderScopeSelector(scopes, targetScope) }
268-
{ this.renderSearchInput({ ...props, className: 'slds-col', bare: true }) }
273+
{ this.renderScopeSelector({ scopes, targetScope, disabled }) }
274+
{ this.renderSearchInput({ ...props, disabled, className: 'slds-col', bare: true }) }
269275
</div>
270276
);
271277
}
@@ -289,6 +295,7 @@ LookupSearch.propTypes = {
289295
),
290296
targetScope: PropTypes.any, // eslint-disable-line
291297
iconAlign: PropTypes.oneOf(ICON_ALIGNS),
298+
disabled: PropTypes.bool,
292299
onKeyDown: PropTypes.func,
293300
onBlur: PropTypes.func,
294301
onChange: PropTypes.func,

stories/LookupStories.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,22 @@ storiesOf('Lookup', module)
261261
onComplete={ action('complete') }
262262
/>
263263
))
264+
.addWithInfo('Multi Scope - Disabled', 'Lookup component which allows multiples scopes selection, but in disabled status', () => (
265+
<Lookup
266+
label='Lookup (multiple scope, disabled)'
267+
opened={ false }
268+
selected={ null }
269+
disabled
270+
scopes={ LOOKUP_SCOPES }
271+
onScopeMenuClick={ action('scopeMenuClick') }
272+
onScopeChange={ action('scopeChange') }
273+
onSearchTextChange={ action('searchTextChange') }
274+
onLookupRequest={ action('lookupRequest') }
275+
onSelect={ action('select') }
276+
onBlur={ action('blur') }
277+
onComplete={ action('complete') }
278+
/>
279+
))
264280
.addWithInfo('Controlled', 'Lookup component whose state is controlled from outside', () => (
265281
<LookupControlled
266282
label='Lookup (Controlled)'

0 commit comments

Comments
 (0)