FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(Select): Add props for hard coded strings by tlabaj · Pull Request #2993 · patternfly/patternfly-react · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .snap  (1) .tsx  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
      • Select.tsx
        • Select.test.tsx.snap
      • SelectDemo.tsx
This file contains hidden or 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
Expand Up @@ -34,8 +34,12 @@ export interface SelectProps
isDisabled?: boolean;
/** Flag to indicate if the typeahead select allows new items */
isCreatable?: boolean;
/** Text displayed in typeahead select to prompt the user to create an item */
createText?: string;
/** Title text of Select */
placeholderText?: string | React.ReactNode;
/** Text to display in typeahead select when no results are found **/
noResultsFoundText?: string;
/** Selected item */
selections?: string | SelectOptionObject | (string | SelectOptionObject)[];
/** Id for select toggle element */
Expand Down Expand Up @@ -104,7 +108,9 @@ export class Select extends React.Component<SelectProps, SelectState> {
"ariaLabelToggle": 'Options menu',
"ariaLabelRemove": 'Remove',
"selections": '',
"createText": "Create",
"placeholderText": '',
"noResultsFoundText": "No results found",
"variant": SelectVariant.single,
"width": '',
"onClear": Function.prototype,
Expand Down Expand Up @@ -155,7 +161,7 @@ export class Select extends React.Component<SelectProps, SelectState> {
}

onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { onFilter, isCreatable, onCreateOption } = this.props;
const { onFilter, isCreatable, onCreateOption, createText, noResultsFoundText } = this.props;
let typeaheadFilteredChildren;
if (onFilter) {
typeaheadFilteredChildren = onFilter(e);
Expand All @@ -175,13 +181,13 @@ export class Select extends React.Component<SelectProps, SelectState> {
: React.Children.toArray(this.props.children);
}
if (typeaheadFilteredChildren.length === 0) {
!isCreatable && typeaheadFilteredChildren.push(<SelectOption isDisabled key={0} value="No results found" />);
!isCreatable && typeaheadFilteredChildren.push(<SelectOption isDisabled key={0} value={noResultsFoundText} />);
}
if (isCreatable && e.target.value != '') {
const newValue = e.target.value;
typeaheadFilteredChildren.push(
<SelectOption key={0} value={newValue} onClick={() => onCreateOption && onCreateOption(newValue)}>
Create "{newValue}"
{createText} "{newValue}"
</SelectOption>
);
}
Expand Down Expand Up @@ -217,7 +223,7 @@ export class Select extends React.Component<SelectProps, SelectState> {
typeaheadActiveChild &&
(typeaheadActiveChild.innerText ===
this.getDisplay((child as React.ReactElement).props.value.toString(), 'text') ||
(this.props.isCreatable && typeaheadActiveChild.innerText === `Create "${(child as React.ReactElement).props.value}"`))
(this.props.isCreatable && typeaheadActiveChild.innerText === `{createText} "${(child as React.ReactElement).props.value}"`))
})
);
}
Expand All @@ -237,7 +243,7 @@ export class Select extends React.Component<SelectProps, SelectState> {
}

handleTypeaheadKeys = (position: string) => {
const { isExpanded, isCreatable } = this.props;
const { isExpanded, isCreatable, createText } = this.props;
const { typeaheadActiveChild, typeaheadCurrIndex } = this.state;
if (isExpanded) {
if (position === 'enter' && (typeaheadActiveChild || this.refCollection[0])) {
Expand All @@ -263,7 +269,7 @@ export class Select extends React.Component<SelectProps, SelectState> {
typeaheadCurrIndex: nextIndex,
typeaheadActiveChild: this.refCollection[nextIndex],
typeaheadInputValue:
isCreatable && this.refCollection[nextIndex].innerText.includes('Create')
isCreatable && this.refCollection[nextIndex].innerText.includes(createText)
? this.state.creatableValue
: this.refCollection[nextIndex].innerText
});
Expand Down
Loading

Back | FazBrowse Home | New Git URL