-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combobox single selection - Error Text style fix (#3106)
* Fixed combobox single selection css error * Fixed tests
- Loading branch information
Showing
8 changed files
with
529 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
components/combobox/__examples__/inline-single-invalid.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* eslint-disable no-console, react/prop-types */ | ||
import React from 'react'; | ||
import Combobox from '~/components/combobox'; | ||
import Icon from '~/components/icon'; | ||
import comboboxFilterAndLimit from '~/components/combobox/filter'; | ||
import IconSettings from '~/components/icon-settings'; | ||
|
||
const accounts = [ | ||
{ | ||
id: '1', | ||
label: 'Acme', | ||
subTitle: 'Account • San Francisco', | ||
type: 'account', | ||
}, | ||
{ | ||
id: '2', | ||
label: 'Salesforce.com, Inc.', | ||
subTitle: 'Account • San Francisco', | ||
type: 'account', | ||
}, | ||
{ | ||
id: '3', | ||
label: "Paddy's Pub", | ||
subTitle: 'Account • Boston, MA', | ||
type: 'account', | ||
}, | ||
{ | ||
id: '4', | ||
label: 'Tyrell Corp', | ||
subTitle: 'Account • San Francisco, CA', | ||
type: 'account', | ||
}, | ||
{ | ||
id: '5', | ||
label: 'Paper St. Soap Company', | ||
subTitle: 'Account • Beloit, WI', | ||
type: 'account', | ||
}, | ||
{ | ||
id: '6', | ||
label: 'Nakatomi Investments', | ||
subTitle: 'Account • Chicago, IL', | ||
type: 'account', | ||
}, | ||
{ id: '7', label: 'Acme Landscaping', type: 'account' }, | ||
{ | ||
id: '8', | ||
label: 'Acme Construction', | ||
subTitle: 'Account • Grand Marais, MN', | ||
type: 'account', | ||
}, | ||
]; | ||
|
||
const accountsWithIcon = accounts.map((elem) => ({ | ||
...elem, | ||
...{ | ||
icon: ( | ||
<Icon | ||
assistiveText={{ label: 'Account' }} | ||
category="standard" | ||
name={elem.type} | ||
/> | ||
), | ||
}, | ||
})); | ||
|
||
class Example extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
inputValue: '', | ||
selection: [], | ||
}; | ||
} | ||
|
||
render() { | ||
return ( | ||
<IconSettings iconPath="/assets/icons"> | ||
<Combobox | ||
id="combobox-inline-single-invalid" | ||
aria-describedby="combobox-inline-single-error" | ||
events={{ | ||
onChange: (event, { value }) => { | ||
if (this.props.action) { | ||
this.props.action('onChange')(event, value); | ||
} else if (console) { | ||
console.log('onChange', event, value); | ||
} | ||
this.setState({ inputValue: value }); | ||
}, | ||
onRequestRemoveSelectedOption: (event, data) => { | ||
this.setState({ | ||
inputValue: '', | ||
selection: data.selection, | ||
}); | ||
}, | ||
onSubmit: (event, { value }) => { | ||
if (this.props.action) { | ||
this.props.action('onChange')(event, value); | ||
} else if (console) { | ||
console.log('onChange', event, value); | ||
} | ||
this.setState({ | ||
inputValue: '', | ||
selection: [ | ||
...this.state.selection, | ||
{ | ||
label: value, | ||
icon: ( | ||
<Icon | ||
assistiveText={{ label: 'Account' }} | ||
category="standard" | ||
name="account" | ||
/> | ||
), | ||
}, | ||
], | ||
}); | ||
}, | ||
onSelect: (event, data) => { | ||
if (this.props.action) { | ||
this.props.action('onSelect')( | ||
event, | ||
...Object.keys(data).map((key) => data[key]) | ||
); | ||
} else if (console) { | ||
console.log('onSelect', event, data); | ||
} | ||
this.setState({ | ||
inputValue: '', | ||
selection: data.selection, | ||
}); | ||
}, | ||
}} | ||
labels={{ | ||
label: 'Search', | ||
placeholder: 'Search Salesforce', | ||
}} | ||
options={comboboxFilterAndLimit({ | ||
inputValue: this.state.inputValue, | ||
options: accountsWithIcon, | ||
selection: this.state.selection, | ||
})} | ||
selection={this.state.selection} | ||
value={ | ||
this.state.selectedOption | ||
? this.state.selectedOption.label | ||
: this.state.inputValue | ||
} | ||
required | ||
errorText="This field is invalid" | ||
variant="inline-listbox" | ||
/> | ||
</IconSettings> | ||
); | ||
} | ||
} | ||
|
||
Example.displayName = 'ComboboxExample'; | ||
export default Example; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime |
Oops, something went wrong.