Skip to content

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented May 24, 2023

Issue number: resolves #26838


What is the current behavior?

Developers are unable to pass custom HTML as a label to ion-select.

What is the new behavior?

  • Adds a label slot to ion-select so developers can pass custom HTML for the label.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Docs PR: ionic-team/ionic-docs#2971

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the package: core @ionic/core package label May 24, 2023
@liamdebeasi liamdebeasi changed the title Fw 3532 feat(select): add label slot May 24, 2023
@liamdebeasi liamdebeasi marked this pull request as ready for review May 24, 2023 14:29
@liamdebeasi liamdebeasi requested a review from a team as a code owner May 24, 2023 14:29
@@ -576,7 +586,7 @@ export class Select implements ComponentInterface {
label = this.getLabel();
labelText = label ? label.textContent : null;
} else {
labelText = this.label;
labelText = this.labelText;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be this.labelText()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this.labelText is a getter which binds the property to a function. When you look up this.labelText the function is automatically called: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get

@thetaPC thetaPC requested a review from a team May 24, 2023 17:02
Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thetaPC thetaPC requested a review from a team May 24, 2023 17:22
Comment on lines 785 to 796
/**
* If no label is being used, then we
* do not need to estimate the notch width.
*/
!this.hasLabel ||
/**
* If the label property is being used
* then we can render the label text inside
* of the notch and let the browser
* determine the notch size for us.
*/
this.label !== undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: As far as the label checks go, !this.hasLabel || this.label !== undefined is equivalent to this.label === undefined || this.label !== undefined, which is always true, so you could combine these checks into this.labelSlot === null. I can understand wanting to black-box the hasLabel logic in case it changes in the future, though, so feel free to leave this as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concern I have with this change is it does not consider if both the label slot and prop are defined. If we only checked this.labelSlot === null then the code would attempt to set the notch width if both the label slot and prop are defined.

However, I could change the check to something like this:

this.label === undefined && this.labelSlot !== null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, true! Sure, that works for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in ccc3b60

@liamdebeasi liamdebeasi requested a review from averyjohnston May 25, 2023 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants