diff --git a/src/declarativeimports/plasmacomponents3/TextField.qml b/src/declarativeimports/plasmacomponents3/TextField.qml --- a/src/declarativeimports/plasmacomponents3/TextField.qml +++ b/src/declarativeimports/plasmacomponents3/TextField.qml @@ -28,6 +28,12 @@ T.TextField { id: control + /** + * Whether the button to clear the text from TextField is visible. + * @since 5.49 + */ + property bool clearButtonShown: false + implicitWidth: Math.max(units.gridUnit * 8, placeholderText ? placeholder.implicitWidth + leftPadding + rightPadding : 0) || contentWidth + leftPadding + rightPadding @@ -74,4 +80,31 @@ prefix: "base" } } + + PlasmaCore.IconItem { + //ltr confusingly refers to the direction of the arrow in the icon, not the text direction which it should be used in + anchors { + right: control.right + rightMargin: units.smallSpacing + verticalCenter: parent.verticalCenter + } + source: clearButtonShown ? (LayoutMirroring.enabled ? "edit-clear-locationbar-ltr" : "edit-clear-locationbar-rtl") : "" + height: Math.max(control.height * 0.8, units.iconSizes.small) + width: height + opacity: (control.length > 0 && clearButtonShown && control.enabled) ? 1 : 0 + visible: opacity > 0 + Behavior on opacity { + NumberAnimation { + duration: units.longDuration + easing.type: Easing.InOutQuad + } + } + MouseArea { + anchors.fill: parent + onClicked: { + control.text = "" + control.forceActiveFocus() + } + } + } }