Bug 457466 - Placeholder text is not elided in TextField
Summary: Placeholder text is not elided in TextField
Status: RESOLVED FIXED
Alias: None
Product: libplasma
Classification: Frameworks and Libraries
Component: components (show other bugs)
Version: 5.96.0
Platform: Other Linux
: NOR minor
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-03 22:49 UTC by 2anwe
Modified: 2023-12-08 15:59 UTC (History)
7 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.98.0
Sentry Crash Report:


Attachments
Bug with kde NetworkManager (113.47 KB, image/png)
2022-08-03 22:49 UTC, 2anwe
Details
Steps to reproduce (3.87 MB, video/mp4)
2022-08-05 21:16 UTC, 2anwe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description 2anwe 2022-08-03 22:49:51 UTC
Created attachment 151098 [details]
Bug with kde NetworkManager

Bug with kde NetworkManager

SOFTWARE/OS VERSIONS

Linux/KDE Plasma: OpenSUSE Tumbleweed
KDE Plasma Version: 5.25.3
KDE Frameworks Version: 5.96.0
Qt Version: 5.15.5
Comment 1 2anwe 2022-08-03 22:50:55 UTC
Comment on attachment 151098 [details]
Bug with kde NetworkManager

Bug with kde NetworkManager

SOFTWARE/OS VERSIONS

Linux/KDE Plasma: OpenSUSE Tumbleweed
KDE Plasma Version: 5.25.3
KDE Frameworks Version: 5.96.0
Qt Version: 5.15.5
Comment 2 Chris Holland 2022-08-04 19:05:43 UTC
Hmm, plasma-nm uses PlasmaExtras.SearchField for the search field.
https://invent.kde.org/plasma/plasma-nm/-/blob/master/applet/contents/ui/Toolbar.qml#L150
Comment 3 Nate Graham 2022-08-04 19:18:34 UTC
How did you get it in this state? Is that the placeholder text, or did you type text into the text field?
Comment 4 Chris Holland 2022-08-04 19:31:35 UTC
I was able to confirm this bug in OpenSUSE TW as well:
https://i.imgur.com/wpxzFhG.png

1. Comment out all the `visible: __` stuff in plasma-nm's Toolbar.qml to show all the extra fluff hidden on a non-wifi PC which shrinks the SearchField width.
2. Resizing the plasmoid popup with Meta+RightClick+Drag to make the SearchField even smaller.

The SearchField seems to use PC3.TextField at it's base. It has `elide: Text.ElideRight` so I am not sure what's broken.

* https://invent.kde.org/frameworks/plasma-framework/-/blob/master/src/declarativeimports/plasmaextracomponents/qml/SearchField.qml
* https://invent.kde.org/frameworks/plasma-framework/-/blob/master/src/declarativeimports/plasmaextracomponents/qml/ActionTextField.qml
* https://invent.kde.org/frameworks/plasma-framework/-/blame/master/src/declarativeimports/plasmacomponents3/TextField.qml#L122-138

    Label {
        id: placeholder
        x: control.leftPadding
        width: control.availableWidth
        text: control.placeholderText
        horizontalAlignment: control.horizontalAlignment
        elide: Text.ElideRight
        ...
Comment 5 Nate Graham 2022-08-04 19:35:46 UTC
Can you reproduce it in other widgets, or just this one?
Comment 6 Chris Holland 2022-08-04 21:30:02 UTC
Searching 3175 files for "PlasmaExtras.SearchField":

kdeplasma-addons/applets/dict/package/contents/ui/main.qml
kwin/src/effects/windowview/qml/main.qml
plasma-desktop/applets/kicker/package/contents/ui/MenuRepresentation.qml
plasma-desktop/applets/kickoff/package/contents/ui/Header.qml
plasma-desktop/desktoppackage/contents/activitymanager/Heading.qml
plasma-desktop/desktoppackage/contents/explorer/WidgetExplorer.qml
plasma-framework/src/declarativeimports/plasmaextracomponents/qml/SearchField.qml
plasma-nm/applet/contents/ui/Toolbar.qml
plasma-workspace/applets/clipboard/contents/ui/ClipboardPage.qml
plasma-workspace/lookandfeel/contents/runcommand/RunCommand.qml

Adding `Item { Layout.minimumWidth: 300 }` to kickoff's Header.qml can also duplicate this bug:
https://i.imgur.com/NklXX2t.png
Comment 7 ratijas 2022-08-04 21:49:55 UTC
Text fields implementations are waiting for someone to redo their layout, tbh. Also, in my opinion, placeholders should be rewritten with padding and expanded API — an option to show it to the right of a user-edited text too.
Comment 8 Chris Holland 2022-08-04 22:12:39 UTC
After editing /usr/lib64/qt5/qml/org/kde/plasma/components.3/TextField.qml in OpenSuse TW, I've noticed that `control.availableWidth` is `undefined`, which means the width of the placeholder is undefined.

    T.TextField {
        id: control

        Rectangle {
            border.color: "yellow"
            border.width: 1
            color: "transparent"
            x: control.leftPadding
            y: control.topPadding
            width: control.availableWidth
            height: control.availableHeight
            onWidthChanged: console.log('availableWidth', control.availableWidth)
            Component.onCompleted: console.log('availableWidth', control.availableWidth)
        }
        ...


I assume this is suppose to be `QQC2.Control.availableWidth` right?
* https://doc.qt.io/qt-6/qml-qtquick-controls2-control.html#availableWidth-prop

Except that `QQC2.TextField` does not inherit `QQC2.Control`.
* https://doc.qt.io/qt-6/qml-qtquick-controls2-textfield.html
* https://doc.qt.io/qt-6/qml-qtquick-textinput.html
* https://doc.qt.io/qt-6/qml-qtquick-item.html
* https://github.com/qt/qtdeclarative/blob/dev/src/quicktemplates2/qquicktextfield_p.h
* https://github.com/qt/qtdeclarative/blob/dev/src/quick/items/qquicktextinput_p.h

Seems there was a bug introduced in the commit that added `control.availableWidth`. Git blame:
https://invent.kde.org/frameworks/plasma-framework/-/commit/52b9c9e94aec30ff8f0a05b0cf9a84e187f6bf61
https://invent.kde.org/frameworks/plasma-framework/-/merge_requests/213
Comment 9 ratijas 2022-08-04 22:15:59 UTC
> Except that `QQC2.TextField` does not inherit `QQC2.Control`.

Yep, welcome to the consistency of QQC2 :-\

Thanks for the investigation! It should be trivial to fix by replacing availableWidth with control's `width - leftPadding - rightPadding`.
Comment 10 2anwe 2022-08-05 12:13:24 UTC
(In reply to Nate Graham from comment #3)
> How did you get it in this state? Is that the placeholder text, or did you
> type text into the text field?

This is placeholder text.
Comment 11 2anwe 2022-08-05 12:36:22 UTC
(In reply to Nate Graham from comment #5)
> Can you reproduce it in other widgets, or just this one?

Just this one.
Comment 12 2anwe 2022-08-05 21:16:48 UTC
Created attachment 151137 [details]
Steps to reproduce