-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(select): add helperText and errorText properties #30143
Open
brandyscarney
wants to merge
14
commits into
feature-8.5
Choose a base branch
from
ROU-11551
base: feature-8.5
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5acf8ab
feat(select): add helperText and errorText properties
brandyscarney d147f89
test(select): add e2e test for bottom content
brandyscarney 51e7920
chore(): add updated snapshots
brandyscarney e84c783
chore: api
brandyscarney c610a03
line break
brandyscarney 4c648d3
feat(select): add css vars for color, screenshot tests and updated sn…
brandyscarney 0c0082c
style: build and lint
brandyscarney 72e9135
refactor(select): remove added css vars in favor of parts
brandyscarney b2695f6
test(e2e): update e2e test for parts
brandyscarney fc8412f
chore(): add updated snapshots
brandyscarney f6da04d
style: lint
brandyscarney 66d6b07
test(select): hide toggle fill button on ios
brandyscarney eee3c8b
Merge branch 'feature-8.5' into ROU-11551
brandyscarney 62d23fb
Merge branch 'feature-8.5' into ROU-11551
brandyscarney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,9 @@ import type { SelectChangeEventDetail, SelectInterface, SelectCompareFn } from ' | |
* @part icon - The select icon container. | ||
* @part container - The container for the selected text or placeholder. | ||
* @part label - The label text describing the select. | ||
* @part supporting-text - Supporting text displayed beneath the select. | ||
* @part helper-text - Supporting text displayed beneath the select when the select is valid. | ||
* @part error-text - Supporting text displayed beneath the select when the select is invalid and touched. | ||
*/ | ||
@Component({ | ||
tag: 'ion-select', | ||
|
@@ -52,6 +55,8 @@ import type { SelectChangeEventDetail, SelectInterface, SelectCompareFn } from ' | |
}) | ||
export class Select implements ComponentInterface { | ||
private inputId = `ion-sel-${selectIds++}`; | ||
private helperTextId = `${this.inputId}-helper-text`; | ||
private errorTextId = `${this.inputId}-error-text`; | ||
private overlay?: OverlaySelect; | ||
private focusEl?: HTMLButtonElement; | ||
private mutationO?: MutationObserver; | ||
|
@@ -98,6 +103,16 @@ export class Select implements ComponentInterface { | |
*/ | ||
@Prop() fill?: 'outline' | 'solid'; | ||
|
||
/** | ||
* Text that is placed under the select and displayed when an error is detected. | ||
*/ | ||
@Prop() errorText?: string; | ||
|
||
/** | ||
* Text that is placed under the select and displayed when no error is detected. | ||
*/ | ||
@Prop() helperText?: string; | ||
|
||
/** | ||
* The interface the select should use: `action-sheet`, `popover`, `alert`, or `modal`. | ||
*/ | ||
|
@@ -983,13 +998,64 @@ export class Select implements ComponentInterface { | |
aria-label={this.ariaLabel} | ||
aria-haspopup="dialog" | ||
aria-expanded={`${isExpanded}`} | ||
aria-describedby={this.getHintTextID()} | ||
aria-invalid={this.getHintTextID() === this.errorTextId} | ||
onFocus={this.onFocus} | ||
onBlur={this.onBlur} | ||
ref={(focusEl) => (this.focusEl = focusEl)} | ||
></button> | ||
); | ||
} | ||
|
||
private getHintTextID(): string | undefined { | ||
const { el, helperText, errorText, helperTextId, errorTextId } = this; | ||
|
||
if (el.classList.contains('ion-touched') && el.classList.contains('ion-invalid') && errorText) { | ||
return errorTextId; | ||
} | ||
|
||
if (helperText) { | ||
return helperTextId; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
/** | ||
* Renders the helper text or error text values | ||
*/ | ||
private renderHintText() { | ||
const { helperText, errorText, helperTextId, errorTextId } = this; | ||
|
||
return [ | ||
<div id={helperTextId} class="helper-text" part="supporting-text helper-text"> | ||
{helperText} | ||
</div>, | ||
<div id={errorTextId} class="error-text" part="supporting-text error-text"> | ||
{errorText} | ||
</div>, | ||
Comment on lines
+1031
to
+1036
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the ion-select::part(supporting-text) {
font-size: 20px;
} but if we think it should only be the one part they could write this without it: ion-select::part(helper-text),
ion-select::part(error-text) {
font-size: 20px;
} I am copying Material Design 2 and Material Design 3 naming here, but let me know if there are other ideas. |
||
]; | ||
} | ||
|
||
/** | ||
* Responsible for rendering helper text, and error text. This element | ||
* should only be rendered if hint text is set. | ||
*/ | ||
private renderBottomContent() { | ||
const { helperText, errorText } = this; | ||
|
||
/** | ||
* undefined and empty string values should | ||
* be treated as not having helper/error text. | ||
*/ | ||
const hasHintText = !!helperText || !!errorText; | ||
if (!hasHintText) { | ||
return; | ||
} | ||
|
||
return <div class="select-bottom">{this.renderHintText()}</div>; | ||
} | ||
|
||
render() { | ||
const { disabled, el, isExpanded, expandedIcon, labelPlacement, justify, placeholder, fill, shape, name, value } = | ||
this; | ||
|
@@ -1069,6 +1135,7 @@ export class Select implements ComponentInterface { | |
{hasFloatingOrStackedLabel && this.renderSelectIcon()} | ||
{shouldRenderHighlight && <div class="select-highlight"></div>} | ||
</label> | ||
{this.renderBottomContent()} | ||
</Host> | ||
); | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be beneficial to update
@prop --highlight-color-invalid
definition to also mention that it will also change error text?ionic-framework/core/src/components/select/select.scss
Line 19 in 66d6b07