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

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

merged 16 commits into from
Jan 26, 2024

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented Jan 2, 2024

Issue number: resolves #28769


What is the current behavior?

As part of #28146, we allowed text wrapping inside of ion-item for accessibility purposes. One of the behaviors we added was to allow start, default, and end slotted containers to wrap to the next line to align with the iOS spec. However, this decision was based on an incorrect assumption.

The following screenshot shows the Settings app on iOS:

default scale 310% scale
Frame 4 Frame 5

At the default scale, the blue icon is in the iOS equivalent of the "start" slot, "Bluetooth" is in the default slot, and "On" is in the "end" slot. We incorrectly assumed the same markup was true when scaling the text up. However, at 310% scale the icon, "Bluetooth" text, and "On" text all become part of the default slot in a single container that wraps. You can tell because the bottom border runs underneath the blue icon at 310% whereas it does not at the default scale. This allows the text to wrap underneath the blue icon. When we originally implemented #28146 we thought that this meant the start, default, and end slot containers should wrap to the next line.

I further validated this behavior by creating an app with Swift UI. I created a list of items where each item has the native equivalent of a checkbox in the start slot and multiple ion-labels in the default slot of the item:

Default Scale 310% Scale
IMG_3133 IMG_3134

The content within each label wraps within the container, but the containers themselves never wrap to the next line.

Demo code:

import SwiftUI

struct ContentView: View {
    struct Item: Identifiable, Hashable {
        let id = UUID()
    }

    private var items = [
        Item(),
        Item(),
        Item(),
        Item(),
        Item()
    ]

    @State private var multiSelection = Set<UUID>()

    var body: some View {
        NavigationView {
            List(items, selection: $multiSelection) {_ in
                HStack {
                    Text("Column 1 with really long text")
                    Text("Column 2 with really long text")
                    Text("Column 3 with really long text")
                    Text("Column 4 with really long text")
                }
            }
            .toolbar { EditButton() }
        }
        Text("\(multiSelection.count) selections")
    }
}

#Preview {
    ContentView()
}

What is the new behavior?

  • This PR removes the ability for the start, default, and end slot containers to wrap to the next line. This behavior aligns with pre-v7.6.0 behaviors. The containers inside of the default slot will not wrap to the next line. However, content within each container (such as text within an ion-label) will continue to wrap to meet the team's accessibility requirements.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev build: 7.6.5-dev.11704916749.1e64a3a7

@github-actions github-actions bot removed the package: vue @ionic/vue package label Jan 10, 2024
* 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.

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!!

@liamdebeasi liamdebeasi marked this pull request as ready for review January 10, 2024 22:26
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, works as discussed

@liamdebeasi
Copy link
Contributor Author

liamdebeasi commented Jan 19, 2024

I need to do some clean up and address feedback, so I'll re-request for review when I'm ready 😄

@liamdebeasi liamdebeasi marked this pull request as draft January 19, 2024 18:04
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.

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.

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.

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.

@liamdebeasi liamdebeasi marked this pull request as ready for review January 19, 2024 19:49
@liamdebeasi
Copy link
Contributor Author

I made a few more changes, so re-requesting review.

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.

Still LGTM, re-request me if the code changes due to this thread.

@liamdebeasi liamdebeasi added this pull request to the merge queue Jan 26, 2024
@liamdebeasi liamdebeasi removed this pull request from the merge queue due to a manual request Jan 26, 2024
@liamdebeasi liamdebeasi added this pull request to the merge queue Jan 26, 2024
Merged via the queue into main with commit 9448783 Jan 26, 2024
46 checks passed
@liamdebeasi liamdebeasi deleted the ld/wrap-revision branch January 26, 2024 22:25
github-merge-queue bot pushed a commit that referenced this pull request Feb 14, 2024
Issue number: resolves #29033

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

In #28773 I resolved
several incorrect behaviors with Items related to text wrapping.
However, it looks like I missed the removal of
https://github.com/ionic-team/ionic-framework/pull/28146/files#diff-4a1156704dbf45b0dad273b6909b190ca45e4380aa7378ba88d0dd7d48d7d473R37
which caused the issue to persist when adding a label to the end slot.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Removed logic that caused `ion-label` to grow larger than it needed to
be

| `main` | branch |
| - | - |
| ![Screenshot 2024-02-13 at 11 20
43 AM](https://github.com/ionic-team/ionic-framework/assets/2721089/3fbddd04-d4b5-474c-ab9c-4d9c6e88f758)
| ![Screenshot 2024-02-13 at 11 21
17 AM](https://github.com/ionic-team/ionic-framework/assets/2721089/188eda24-ec6f-4ba7-b3ed-2993d93b1cc7)
|

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!--
  If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
  2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#footer
for more information.
-->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.7.2-dev.11707840956.16e27b4c`

---------

Co-authored-by: ionitron <[email protected]>
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.

bug: item start and end slots wrap to next line
5 participants