Skip to content

Commit

Permalink
fix: use label as placeholder when there is no placeholder set #36
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-mota committed Dec 28, 2024
1 parent 5211cfb commit bb5d1ce
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 41 deletions.
36 changes: 21 additions & 15 deletions components/select/demo/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@ The auro-select element is a wrapper for auro-dropdown and auro-menu to create a

## Properties

| Property | Attribute | Type | Default | Description |
|---------------------------------|---------------------------------|-----------|------------------------|--------------------------------------------------|
| [disabled](#disabled) | `disabled` | `Boolean` | | When attribute is present element shows disabled state. |
| [error](#error) | `error` | `String` | | When defined, sets persistent validity to `customError` and sets `setCustomValidity` = attribute value. |
| [flexMenuWidth](#flexMenuWidth) | `flexMenuWidth` | `Boolean` | | If set, makes dropdown bib width match the size of the content, rather than the width of the trigger. |
| [noCheckmark](#noCheckmark) | `noCheckmark` | `Boolean` | | When true, checkmark on selected option will no longer be present. |
| [noValidate](#noValidate) | `noValidate` | `Boolean` | | If set, disables auto-validation on blur. |
| [optionSelected](#optionSelected) | `optionSelected` | `Object` | "undefined" | Specifies the current selected menuOption. |
| [placeholder](#placeholder) | `placeholder` | `String` | "Please select option" | Define placeholder text to display before a value is manually selected. |
| [required](#required) | `required` | `Boolean` | | Populates the `required` attribute on the element. Used for client-side validation. |
| [setCustomValidity](#setCustomValidity) | `setCustomValidity` | `String` | | Sets a custom help text message to display for all validityStates. |
| [setCustomValidityCustomError](#setCustomValidityCustomError) | `setCustomValidityCustomError` | `String` | | Custom help text message to display when validity = `customError`. |
| [setCustomValidityValueMissing](#setCustomValidityValueMissing) | `setCustomValidityValueMissing` | `String` | | Custom help text message to display when validity = `valueMissing`. |
| [validity](#validity) | `validity` | `String` | "undefined" | Specifies the `validityState` this element is in. |
| [value](#value) | `value` | `String` | | Value selected for the component. |
| Property | Attribute | Type | Default | Description |
|---------------------------------|---------------------------------|-----------|-------------|--------------------------------------------------|
| [disabled](#disabled) | `disabled` | `Boolean` | | When attribute is present element shows disabled state. |
| [error](#error) | `error` | `String` | | When defined, sets persistent validity to `customError` and sets `setCustomValidity` = attribute value. |
| [flexMenuWidth](#flexMenuWidth) | `flexMenuWidth` | `Boolean` | | If set, makes dropdown bib width match the size of the content, rather than the width of the trigger. |
| [noCheckmark](#noCheckmark) | `noCheckmark` | `Boolean` | | When true, checkmark on selected option will no longer be present. |
| [noValidate](#noValidate) | `noValidate` | `Boolean` | | If set, disables auto-validation on blur. |
| [optionSelected](#optionSelected) | `optionSelected` | `Object` | "undefined" | Specifies the current selected menuOption. |
| [placeholder](#placeholder) | `placeholder` | `String` | "" | Define placeholder text to display before a value is manually selected. |
| [required](#required) | `required` | `Boolean` | | Populates the `required` attribute on the element. Used for client-side validation. |
| [setCustomValidity](#setCustomValidity) | `setCustomValidity` | `String` | | Sets a custom help text message to display for all validityStates. |
| [setCustomValidityCustomError](#setCustomValidityCustomError) | `setCustomValidityCustomError` | `String` | | Custom help text message to display when validity = `customError`. |
| [setCustomValidityValueMissing](#setCustomValidityValueMissing) | `setCustomValidityValueMissing` | `String` | | Custom help text message to display when validity = `valueMissing`. |
| [validity](#validity) | `validity` | `String` | "undefined" | Specifies the `validityState` this element is in. |
| [value](#value) | `value` | `String` | | Value selected for the component. |

## Methods

| Method | Type |
|-------------------------|----------------------|
| [handleLabelSlotChange](#handleLabelSlotChange) | `(event: any): void` |

## Events

Expand Down
21 changes: 17 additions & 4 deletions components/select/demo/api.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -3297,7 +3297,7 @@ AuroDropdown.register();

var dropdownVersion = '3.0.0';

var styleCss$3 = i$b`*,*:before,*:after{box-sizing:border-box}@media(prefers-reduced-motion: reduce){*,*:before,*:after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}}*:focus-visible{outline:0}*:focus-visible{outline:0}:focus:not(:focus-visible){outline:3px solid transparent}.util_displayInline{display:inline}.util_displayInlineBlock{display:inline-block}.util_displayBlock{display:block}.util_displayFlex{display:flex}.util_displayHidden{display:none}.util_displayHiddenVisually{position:absolute;overflow:hidden;clip:rect(1px, 1px, 1px, 1px);width:1px;height:1px;padding:0;border:0}[slot=trigger]{width:100%;padding:0;border:0;cursor:pointer;font-family:inherit;font-size:inherit;text-align:left}[slot=trigger] .nestingSpacer{display:none}:host [auro-dropdown]{position:relative}:host [auro-dropdown]::part(trigger){max-height:var(--ds-size-300, 1.5rem)}:host [auro-dropdown]::part(popover){max-width:-webkit-fill-available;overflow-y:scroll}:host([disabled]) *{user-select:none}.outerWrapper{position:relative}auro-menuoption{pointer-events:none}.menuWrapper{padding:var(--ds-size-50, 0.25rem) 0}.selectElement-helpText{margin:var(--ds-size-50, 0.25rem) 0;font-size:var(--ds-text-body-size-xs, 0.75rem);line-height:1rem}`;
var styleCss$3 = i$b`*,*:before,*:after{box-sizing:border-box}@media(prefers-reduced-motion: reduce){*,*:before,*:after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}}*:focus-visible{outline:0}*:focus-visible{outline:0}:focus:not(:focus-visible){outline:3px solid transparent}.util_displayInline{display:inline}.util_displayInlineBlock{display:inline-block}.util_displayBlock{display:block}.util_displayFlex{display:flex}.util_displayHidden{display:none}.util_displayHiddenVisually{position:absolute;overflow:hidden;clip:rect(1px, 1px, 1px, 1px);width:1px;height:1px;padding:0;border:0}[slot=trigger]{width:100%;padding:0;border:0;cursor:pointer;font-family:inherit;font-size:inherit;text-align:left}[slot=trigger] .nestingSpacer{display:none}:host [auro-dropdown]{position:relative}:host [auro-dropdown]::part(trigger){max-height:var(--ds-size-300, 1.5rem)}:host [auro-dropdown]::part(popover){max-width:-webkit-fill-available;overflow-y:scroll}:host([disabled]) *{user-select:none}[slot=label].hidden{position:absolute;opacity:0}.outerWrapper{position:relative}auro-menuoption{pointer-events:none}.menuWrapper{padding:var(--ds-size-50, 0.25rem) 0}.selectElement-helpText{margin:var(--ds-size-50, 0.25rem) 0;font-size:var(--ds-text-body-size-xs, 0.75rem);line-height:1rem}`;

var colorCss$3 = i$b`*,*:before,*:after{box-sizing:border-box}@media(prefers-reduced-motion: reduce){*,*:before,*:after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}}*:focus-visible{outline:0}*:focus-visible{outline:0}:focus:not(:focus-visible){outline:3px solid transparent}.util_displayInline{display:inline}.util_displayInlineBlock{display:inline-block}.util_displayBlock{display:block}.util_displayFlex{display:flex}.util_displayHidden{display:none}.util_displayHiddenVisually{position:absolute;overflow:hidden;clip:rect(1px, 1px, 1px, 1px);width:1px;height:1px;padding:0;border:0}:host [auro-dropdown]::part(trigger):hover{--ds-auro-dropdown-trigger-container-color: rgba(0 0 0 / 0.06)}:host([disabled]) *{color:var(--ds-color-text-ui-disabled-default, #adadad)}.placeholder{color:var(--ds-auro-select-placeholder-text-color)}`;

Expand Down Expand Up @@ -3337,7 +3337,7 @@ class AuroSelect extends r$4 {
constructor() {
super();

this.placeholder = 'Please select option';
this.placeholder = '';
this.optionSelected = undefined;
this.validity = undefined;

Expand Down Expand Up @@ -3376,6 +3376,12 @@ class AuroSelect extends r$4 {
* @private
*/
this.isHiddenWhileLoading = false;


/**
* @private
*/
this.labelText = undefined;
}

/**
Expand Down Expand Up @@ -3800,6 +3806,11 @@ class AuroSelect extends r$4 {
});
}

handleLabelSlotChange(event) {
const slots = event.target.assignedNodes();
this.labelText = slots ? slots.map((slot) => slot.textContent) : undefined;
}

// When using auroElement, use the following attribute and function when hiding content from screen readers.
// aria-hidden="${this.hideAudible(this.hiddenAudible)}"

Expand Down Expand Up @@ -3831,11 +3842,13 @@ class AuroSelect extends r$4 {
chevron
part="dropdown">
<span slot="trigger" aria-haspopup="true" id="triggerFocus">
${this.value ? this.displayValue : u$3`<span class="placeholder">${this.placeholder}</span>`}
${this.value ? this.displayValue : u$3`<span class="placeholder">${this.placeholder || this.labelText}</span>`}
</span>
<div class="menuWrapper">
</div>
<slot name="label" slot="label"></slot>
<span slot="label" class="${!this.placeholder&&!this.value ? 'hidden' : ''}">
<slot name="label" @slotchange="${(event) => this.handleLabelSlotChange(event)}"></slot>
</span>
<span slot="helpText">
${!this.validity || this.validity === undefined || this.validity === 'valid'
? u$3`
Expand Down
21 changes: 17 additions & 4 deletions components/select/demo/index.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -3207,7 +3207,7 @@ AuroDropdown.register();

var dropdownVersion = '3.0.0';

var styleCss$3 = i$b`*,*:before,*:after{box-sizing:border-box}@media(prefers-reduced-motion: reduce){*,*:before,*:after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}}*:focus-visible{outline:0}*:focus-visible{outline:0}:focus:not(:focus-visible){outline:3px solid transparent}.util_displayInline{display:inline}.util_displayInlineBlock{display:inline-block}.util_displayBlock{display:block}.util_displayFlex{display:flex}.util_displayHidden{display:none}.util_displayHiddenVisually{position:absolute;overflow:hidden;clip:rect(1px, 1px, 1px, 1px);width:1px;height:1px;padding:0;border:0}[slot=trigger]{width:100%;padding:0;border:0;cursor:pointer;font-family:inherit;font-size:inherit;text-align:left}[slot=trigger] .nestingSpacer{display:none}:host [auro-dropdown]{position:relative}:host [auro-dropdown]::part(trigger){max-height:var(--ds-size-300, 1.5rem)}:host [auro-dropdown]::part(popover){max-width:-webkit-fill-available;overflow-y:scroll}:host([disabled]) *{user-select:none}.outerWrapper{position:relative}auro-menuoption{pointer-events:none}.menuWrapper{padding:var(--ds-size-50, 0.25rem) 0}.selectElement-helpText{margin:var(--ds-size-50, 0.25rem) 0;font-size:var(--ds-text-body-size-xs, 0.75rem);line-height:1rem}`;
var styleCss$3 = i$b`*,*:before,*:after{box-sizing:border-box}@media(prefers-reduced-motion: reduce){*,*:before,*:after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}}*:focus-visible{outline:0}*:focus-visible{outline:0}:focus:not(:focus-visible){outline:3px solid transparent}.util_displayInline{display:inline}.util_displayInlineBlock{display:inline-block}.util_displayBlock{display:block}.util_displayFlex{display:flex}.util_displayHidden{display:none}.util_displayHiddenVisually{position:absolute;overflow:hidden;clip:rect(1px, 1px, 1px, 1px);width:1px;height:1px;padding:0;border:0}[slot=trigger]{width:100%;padding:0;border:0;cursor:pointer;font-family:inherit;font-size:inherit;text-align:left}[slot=trigger] .nestingSpacer{display:none}:host [auro-dropdown]{position:relative}:host [auro-dropdown]::part(trigger){max-height:var(--ds-size-300, 1.5rem)}:host [auro-dropdown]::part(popover){max-width:-webkit-fill-available;overflow-y:scroll}:host([disabled]) *{user-select:none}[slot=label].hidden{position:absolute;opacity:0}.outerWrapper{position:relative}auro-menuoption{pointer-events:none}.menuWrapper{padding:var(--ds-size-50, 0.25rem) 0}.selectElement-helpText{margin:var(--ds-size-50, 0.25rem) 0;font-size:var(--ds-text-body-size-xs, 0.75rem);line-height:1rem}`;

var colorCss$3 = i$b`*,*:before,*:after{box-sizing:border-box}@media(prefers-reduced-motion: reduce){*,*:before,*:after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}}*:focus-visible{outline:0}*:focus-visible{outline:0}:focus:not(:focus-visible){outline:3px solid transparent}.util_displayInline{display:inline}.util_displayInlineBlock{display:inline-block}.util_displayBlock{display:block}.util_displayFlex{display:flex}.util_displayHidden{display:none}.util_displayHiddenVisually{position:absolute;overflow:hidden;clip:rect(1px, 1px, 1px, 1px);width:1px;height:1px;padding:0;border:0}:host [auro-dropdown]::part(trigger):hover{--ds-auro-dropdown-trigger-container-color: rgba(0 0 0 / 0.06)}:host([disabled]) *{color:var(--ds-color-text-ui-disabled-default, #adadad)}.placeholder{color:var(--ds-auro-select-placeholder-text-color)}`;

Expand Down Expand Up @@ -3247,7 +3247,7 @@ class AuroSelect extends r$4 {
constructor() {
super();

this.placeholder = 'Please select option';
this.placeholder = '';
this.optionSelected = undefined;
this.validity = undefined;

Expand Down Expand Up @@ -3286,6 +3286,12 @@ class AuroSelect extends r$4 {
* @private
*/
this.isHiddenWhileLoading = false;


/**
* @private
*/
this.labelText = undefined;
}

/**
Expand Down Expand Up @@ -3710,6 +3716,11 @@ class AuroSelect extends r$4 {
});
}

handleLabelSlotChange(event) {
const slots = event.target.assignedNodes();
this.labelText = slots ? slots.map((slot) => slot.textContent) : undefined;
}

// When using auroElement, use the following attribute and function when hiding content from screen readers.
// aria-hidden="${this.hideAudible(this.hiddenAudible)}"

Expand Down Expand Up @@ -3741,11 +3752,13 @@ class AuroSelect extends r$4 {
chevron
part="dropdown">
<span slot="trigger" aria-haspopup="true" id="triggerFocus">
${this.value ? this.displayValue : u$3`<span class="placeholder">${this.placeholder}</span>`}
${this.value ? this.displayValue : u$3`<span class="placeholder">${this.placeholder || this.labelText}</span>`}
</span>
<div class="menuWrapper">
</div>
<slot name="label" slot="label"></slot>
<span slot="label" class="${!this.placeholder&&!this.value ? 'hidden' : ''}">
<slot name="label" @slotchange="${(event) => this.handleLabelSlotChange(event)}"></slot>
</span>
<span slot="helpText">
${!this.validity || this.validity === undefined || this.validity === 'valid'
? u$3`
Expand Down
Loading

0 comments on commit bb5d1ce

Please sign in to comment.