Skip to content
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

fix(item): only default slot content wraps #28773

Merged
merged 16 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the same "wiggling" that we saw in #28146 being undone.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 2 additions & 70 deletions core/src/components/item/item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@
* @prop --highlight-color-valid: The color of the highlight on the item when valid. Only applies to inputs and textareas using the legacy form syntax. DEPRECATED: Highlights can be styled on `ion-input` or `ion-textarea` when using the modern form syntax.
* @prop --highlight-color-invalid: The color of the highlight on the item when invalid. Only applies to inputs and textareas using the legacy form syntax. DEPRECATED: Highlights can be styled on `ion-input` or `ion-textarea` when using the modern form syntax.
*/

/**
* We change the minimum width as the
* font size changes. Using a fixed minimum
* width means that fewer and fewer characters
* can be displayed in the same space as the
* text grows.
*/
--inner-min-width: 4rem;
Copy link
Contributor Author

@liamdebeasi liamdebeasi Jan 10, 2024

Choose a reason for hiding this comment

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

This API was only needed to control when the default slot content should stop wrapping within its container and instead have the container wrap to the next line. Since the container no longer wraps to the next line, this API was removed.

Note that this is a private API so it is not a breaking change.

--border-radius: 0px;
--border-width: 0px;
--border-style: solid;
Expand Down Expand Up @@ -230,11 +221,6 @@
display: flex;
position: relative;

// Flex wrap is required here in order to wrap
// the start slot + .item-inner content that
// doesn't fit on the same line
flex-wrap: wrap;

align-items: inherit;
justify-content: inherit;

Expand All @@ -258,11 +244,6 @@
box-sizing: border-box;
}

// TODO(FW-5289): remove
:host(.item-legacy) .item-native {
flex-wrap: unset;
}

.item-native::-moz-focus-inner {
border: 0;
}
Expand Down Expand Up @@ -307,34 +288,13 @@ button, a {
// This is required to work with an inset highlight
position: relative;

// This flex property is required in order to make
// the elements wrap when there is a slotted start
// element and a label
flex: 1 0 0;
flex: 1;

flex-direction: inherit;

// Flex wrap is required here in order to wrap
// .input-wrapper content + the end slot that
// doesn't fit on the same line
flex-wrap: wrap;

align-items: inherit;
align-self: stretch;

/**
* The min-width defines when the
* content in the default slot should
* stop wrapping/truncating within its own
* container. At this point the entire
* container will wrap to the next line.
*/
min-width: var(--inner-min-width);

// Max width must be set to 100%, otherwise the
// elements will overflow this container instead
// of wrapping
max-width: 100%;
min-height: inherit;

border-width: var(--inner-border-width);
Expand All @@ -346,15 +306,6 @@ button, a {
box-sizing: border-box;
}

// TODO(FW-5289): remove
:host(.item-legacy) .item-inner {
flex: 1;

flex-wrap: unset;

max-width: unset;
}

// Item Bottom
// --------------------------------------------------

Expand Down Expand Up @@ -448,38 +399,19 @@ button, a {
// This flex property is required in order to keep
// the label from shrinking when there are wide
// elements next to it
flex: 1 0 auto;
flex: 1;

flex-direction: inherit;

// Flex wrap is required here in order to wrap
// content in the default slot (such as a label
// and a button) that doesn't fit on the same line
flex-wrap: wrap;

align-items: inherit;
align-self: stretch;

// Max width must be set to 100%, otherwise the
// elements will overflow this container instead
// of wrapping
max-width: 100%;

text-overflow: ellipsis;

overflow: inherit;
box-sizing: border-box;
}

// TODO(FW-5289): remove
:host(.item-legacy) .input-wrapper {
flex: 1;

flex-wrap: unset;

max-width: unset;
}

:host(.item-label-stacked),
:host(.item-label-floating) {
align-items: start;
Expand Down
18 changes: 12 additions & 6 deletions core/src/components/item/test/a11y/item.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,22 @@ configs({ directions: ['ltr'] }).forEach(({ config, screenshot, title }) => {

<ion-list>
<ion-item>
<ion-label>Item</ion-label>
<ion-button>Default</ion-button>
<ion-label>
Item
<ion-button>Default</ion-button>
</ion-label>
</ion-item>
<ion-item>
<ion-label>Item</ion-label>
<ion-button size="small">Small</ion-button>
<ion-label>
Item
<ion-button size="small">Small</ion-button>
</ion-label>
</ion-item>
<ion-item>
<ion-label>Item</ion-label>
<ion-button size="large">Large</ion-button>
<ion-label>
Item
<ion-button size="large">Large</ion-button>
</ion-label>
</ion-item>
</ion-list>
`,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This diff is correct. The icons were in start/end slots which now no longer wrap to the next line.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This diff is correct. The icons were in start/end slots which now no longer wrap to the next line.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Range" is part of the default slot, and "End" is part of the end slot. Previously the "end" slot container would wrap to the next line. However, this was removed because it was incorrect. Now both the default and end slots will appear on the same line, and the default slot will shrink.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 24 additions & 12 deletions core/src/components/note/test/a11y/note.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,45 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {

<ion-list>
<ion-item>
<ion-note slot="start">Really really long note</ion-note>
<ion-label>Label</ion-label>
<ion-label>
<ion-note>Really really long note</ion-note>
Label
</ion-label>
</ion-item>

<ion-item>
<ion-label>Label</ion-label>
<ion-note slot="end">Really really long note</ion-note>
<ion-label>
Label
<ion-note>Really really long note</ion-note>
</ion-label>
</ion-item>

<ion-item>
<ion-note slot="start">Note</ion-note>
<ion-label>Really really long label</ion-label>
<ion-label>
Really really long label
<ion-note>Note</ion-note>
</ion-label>
</ion-item>

<ion-item>
<ion-label>Really really long label</ion-label>
<ion-note slot="end">Note</ion-note>
<ion-label>
Really really long label
<ion-note>Really really long note</ion-note>
</ion-label>
</ion-item>

<ion-item>
<ion-note slot="start">Really really long note</ion-note>
<ion-label>Really really long label</ion-label>
<ion-label>
<ion-note>Really really long note</ion-note>
Really really long label
</ion-label>
</ion-item>

<ion-item>
<ion-label>Really really long label</ion-label>
<ion-note slot="end">Really really long note</ion-note>
<ion-label>
Really really long label
<ion-note>Really really long note</ion-note>
</ion-label>
</ion-item>
</ion-list>
`,
Expand Down
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These screenshot changes are a result of c602b30. This screenshot tries to capture the text wrapping behavior found on native iOS when scaled up to 310%. However, as explained in the PR description, the label and note should really be in the same slot so they can wrap within the container.

Copy link
Member

Choose a reason for hiding this comment

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

How would developers achieve this? We have notes documented as being slotted in items. The slotted notes with long labels are expanding outside of the viewport height at 310% with these changes:

100% 310%
100% 310%

vs. inside of the label at 100% they are not clinging to the sides:

100% 310%
100% 310%

Copy link
Contributor

Choose a reason for hiding this comment

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

I have the same question; is there a way for developers (or us, for that matter) to detect the current font scale and adjust the markup dynamically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is an area where we don't have a great solution right now. I'm not aware of how developers can easily have a long note go from the start slot to the default slot when the font size changes apart from putting the content in both slots and selectively hiding one based on the font size using mod() similar to what we do in datetime.

However, I'd argue having both long notes and long labels in the same item isn't something we should encourage.

According to https://ionicframework.com/docs/api/item#metadata, any notes should be short/to the point such as a count or one/two words.

If developers follow that best practice, they'd get something like this:

Default Scale 310% Scale
IMG_3135 IMG_3136

Copy link
Contributor Author

@liamdebeasi liamdebeasi Jan 19, 2024

Choose a reason for hiding this comment

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

One other idea is you could use a ResizeObserver on an element/container and then do something when that fires. I doubt that would be a very performant way of doing it though.

Copy link
Contributor

@averyjohnston averyjohnston Jan 24, 2024

Choose a reason for hiding this comment

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

Looks like the issue Brandy mentioned in #28773 (comment) is still present; some of the notes have their heights massively expanded with this change. Is that supposed to happen? 😆

Example: https://github.com/ionic-team/ionic-framework/pull/28773/files#diff-8911775ab4bd2c84af54bd46e1bf1a0d54ed17209271e5e0595de243fbf1240b

Copy link
Contributor Author

@liamdebeasi liamdebeasi Jan 24, 2024

Choose a reason for hiding this comment

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

That's why I suggested having the note in ion-label so they can wrap and why I mentioned that the test isn't a great example of best practices. The "Really really long note" text is in the start slot, and the default slot is collapsing to account for the width of the start slot. The text inside of the ion-label is wrapping to the next line, so you essentially have 1 character per line (but the width is so small so you don't see it).

image

The orange/yellow is the ion-label.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, I see. In that case, should we update the test to avoid these long notes in the first place? Wouldn't be the first time we've adjusted tests to match best practices, and this one is particularly sticky since it leads to unnecessarily massive screenshots.

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 d9e034c. Mind taking another look?

Copy link
Contributor

Choose a reason for hiding this comment

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

Muuuch better, thank you!!

Loading