Skip to content

Commit cacdba0

Browse files
authored
fix(ui5-date-picker): add input CSS part for styling (#12559)
fix(ui5-date-picker): add input CSS part for styling #12559 Add input CSS part to DatePicker and TimePicker components to allow styling of the native input element using ::part(input) selector. - Add @csspart input documentation for both components - Forward part attribute to DateTimeInput in templates - Maintains consistency with ui5-input component API - Enables scoping-friendly styling without deep selectors
1 parent 3582597 commit cacdba0

File tree

9 files changed

+34
-0
lines changed

9 files changed

+34
-0
lines changed

packages/main/cypress/specs/DatePicker.cy.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,3 +1937,14 @@ describe("Accessibility", () => {
19371937
.should("have.text", DESCRIPTION);
19381938
});
19391939
});
1940+
1941+
describe("CSS Parts", () => {
1942+
it("DatePicker exposes input CSS part through DateTimeInput", () => {
1943+
cy.mount(<DatePicker />);
1944+
1945+
cy.get<DatePicker>("[ui5-date-picker]")
1946+
.shadow()
1947+
.find("[ui5-datetime-input]")
1948+
.should("have.attr", "part", "input");
1949+
});
1950+
});

packages/main/cypress/specs/TimePicker.cy.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,15 @@ describe("Validation inside a form", () => {
543543
cy.get("#timePicker:invalid")
544544
.should("not.exist", "Timepicker with correct formatted value should not have :invalid CSS class");
545545
});
546+
});
547+
548+
describe("CSS Parts", () => {
549+
it("TimePicker exposes input CSS part through DateTimeInput", () => {
550+
cy.mount(<TimePicker />);
551+
552+
cy.get<TimePicker>("[ui5-time-picker]")
553+
.shadow()
554+
.find("[ui5-datetime-input]")
555+
.should("have.attr", "part", "input");
556+
});
546557
});

packages/main/src/DatePicker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ type Picker = "day" | "month" | "year";
175175
* @constructor
176176
* @extends DateComponentBase
177177
* @public
178+
* @csspart input - Used to style the input element. This part is forwarded to the underlying ui5-input element.
178179
*/
179180

180181
@customElement({

packages/main/src/DatePickerInputTemplate.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default function DatePickerInputTemplate(this: DatePicker) {
1414
data-sap-focus-ref
1515
id={`${this._id}-inner`}
1616
class="ui5-date-picker-input"
17+
part="input"
1718
placeholder={this._placeholder}
1819
type={this.type}
1920
value={this.displayValue}

packages/main/src/TimePicker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ type TimePickerInputEventDetail = TimePickerChangeInputEventDetail;
138138
* @extends UI5Element
139139
* @public
140140
* @since 1.0.0-rc.6
141+
* @csspart input - Used to style the input element. This part is forwarded to the underlying ui5-input element.
141142
*/
142143
@customElement({
143144
tag: "ui5-time-picker",

packages/main/src/TimePickerTemplate.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default function TimePickerTemplate(this: TimePicker) {
1212
data-sap-focus-ref
1313
id={`${this._id}-inner`}
1414
class="ui5-time-picker-input"
15+
part="input"
1516
value={this.value}
1617
placeholder={this._placeholder}
1718
disabled={this.disabled}

packages/main/test/pages/styles/DatePicker.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
background-color: var(--sapBackgroundColor);
77
}
88

9+
#dp6::part(input) {
10+
text-align: right;
911

1012
form ui5-date-picker:invalid {
1113
outline: 2px solid var(--sapNegativeColor);

packages/main/test/pages/styles/DateRangePicker.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
background-color: var(--sapBackgroundColor);
77
}
88

9+
#drpLabel::part(input) {
10+
text-align: right;
11+
}
912
form ui5-daterange-picker:invalid {
1013
outline: 2px solid var(--sapNegativeColor);
1114
}

packages/main/test/pages/styles/TimePicker.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ html,body {
2323
width: 100%
2424
}
2525

26+
#tpLabel::part(input) {
27+
text-align: right;
28+
}
2629
form ui5-time-picker:invalid {
2730
outline: 2px solid var(--sapNegativeColor);
2831
}

0 commit comments

Comments
 (0)