Skip to content

Commit

Permalink
Fixed #1331, Fixed #1332, Fixed #1306
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Apr 16, 2020
1 parent b6b9e21 commit fb10bc5
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ export class Dropdown extends Component {
}

checkValidity() {
return this.nativeSelect.checkValidity;
return this.nativeSelect.checkValidity();
}

componentDidMount() {
Expand Down
3 changes: 3 additions & 0 deletions src/components/multiselect/MultiSelect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import TooltipOptions from '../tooltip/TooltipOptions';

interface MultiSelectProps {
id?: string;
name?: string;
value?: any;
options?: any[];
optionLabel?: string;
Expand All @@ -19,6 +20,8 @@ interface MultiSelectProps {
filterPlaceholder?: string;
tabIndex?: boolean;
dataKey?: string;
inputId?: string;
required?: boolean;
appendTo?: HTMLElement;
tooltip?: any;
tooltipOptions?: TooltipOptions;
Expand Down
26 changes: 25 additions & 1 deletion src/components/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class MultiSelect extends Component {

static defaultProps = {
id: null,
name: null,
value: null,
options: null,
optionLabel: null,
Expand All @@ -29,6 +30,8 @@ export class MultiSelect extends Component {
filterPlaceholder: null,
tabIndex: '0',
dataKey: null,
inputId: null,
required: false,
appendTo: null,
tooltip: null,
tooltipOptions: null,
Expand All @@ -44,6 +47,7 @@ export class MultiSelect extends Component {

static propTypes = {
id: PropTypes.string,
name: PropTypes.string,
value: PropTypes.any,
options: PropTypes.array,
optionLabel: PropTypes.string,
Expand All @@ -60,6 +64,8 @@ export class MultiSelect extends Component {
filterPlaceholder: PropTypes.string,
tabIndex: PropTypes.string,
dataKey: PropTypes.string,
inputId: PropTypes.string,
required: PropTypes.bool,
appendTo: PropTypes.object,
tooltip: PropTypes.string,
tooltipOptions: PropTypes.object,
Expand Down Expand Up @@ -384,6 +390,10 @@ export class MultiSelect extends Component {
return !this.props.value || this.props.value.length === 0;
}

checkValidity() {
return this.nativeSelect.checkValidity();
}

getSelectedItemsLabel() {
let pattern = /{(.*?)}/;
if (pattern.test(this.props.selectedItemsLabel)) {
Expand Down Expand Up @@ -469,9 +479,22 @@ export class MultiSelect extends Component {
);
}

renderHiddenSelect() {
let selectedOptions = this.props.value ? this.props.value.map((option,index) => <option key={this.getOptionLabel(option) + '_' + index} selected value={this.getOptionValue(option)}></option>): null;

return (
<div className="p-hidden-accessible p-multiselect-hidden-select">
<select ref={(el) => this.nativeSelect = el} required={this.props.required} name={this.props.name} tabIndex="-1" aria-hidden="true" multiple>
{selectedOptions}
</select>
</div>
);
}

render() {
let className = classNames('p-multiselect p-component', this.props.className, {'p-disabled': this.props.disabled});
let label = this.renderLabel();
let hiddenSelect = this.renderHiddenSelect();
let items = this.props.options;

if (items) {
Expand All @@ -493,9 +516,10 @@ export class MultiSelect extends Component {

return (
<div id={this.props.id} className={className} onClick={this.onClick} ref={el => this.container = el} style={this.props.style}>
{hiddenSelect}
<div className="p-hidden-accessible">
<input readOnly type="text" onFocus={this.onFocus} onBlur={this.onBlur} ref={el => this.focusInput = el} aria-haspopup="listbox"
aria-labelledby={this.props.ariaLabelledBy}/>
aria-labelledby={this.props.ariaLabelledBy} inputId={this.props.inputId} />
</div>
{label}
<div className="p-multiselect-trigger">
Expand Down
6 changes: 6 additions & 0 deletions src/showcase/dropdown/DropdownDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ carTemplate(option) {
<td>null</td>
<td>Unique identifier of the element.</td>
</tr>
<tr>
<td>name</td>
<td>string</td>
<td>null</td>
<td>Name of the input element.</td>
</tr>
<tr>
<td>value</td>
<td>any</td>
Expand Down
38 changes: 38 additions & 0 deletions src/showcase/multiselect/MultiSelectDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ selectedCarTemplate(option) {
<td>null</td>
<td>Unique identifier of the element.</td>
</tr>
<tr>
<td>name</td>
<td>string</td>
<td>null</td>
<td>Name of the input element.</td>
</tr>
<tr>
<td>value</td>
<td>array</td>
Expand Down Expand Up @@ -377,6 +383,18 @@ selectedCarTemplate(option) {
<td>null</td>
<td>A property to uniquely match the value in options for better performance.</td>
</tr>
<tr>
<td>required</td>
<td>boolean</td>
<td>false</td>
<td>When present, it specifies that an input field must be filled out before submitting the form.</td>
</tr>
<tr>
<td>inputId</td>
<td>string</td>
<td>null</td>
<td>Identifier of the focusable input.</td>
</tr>
<tr>
<td>tooltip</td>
<td>any</td>
Expand Down Expand Up @@ -461,6 +479,26 @@ selectedCarTemplate(option) {
</table>
</div>

<h3>Methods</h3>
<div className="doc-tablewrapper">
<table className="doc-table">
<thead>
<tr>
<th>Name</th>
<th>Parameters</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>checkValidity</td>
<td>-</td>
<td>Checks whether the native hidden select element has any constraints and returns a boolean for the result.</td>
</tr>
</tbody>
</table>
</div>

<h3>Styling</h3>
<p>Following is the list of structural style classes, for theming classes visit <Link to="/theming"> theming</Link> page.</p>
<div className="doc-tablewrapper">
Expand Down

0 comments on commit fb10bc5

Please sign in to comment.