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

feat(core/date-dropdown): add disabled property #1264

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/dry-avocados-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siemens/ix': minor
---

feat(core/date-dropdown): add disabled property
4 changes: 2 additions & 2 deletions packages/angular/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,15 @@ export declare interface IxContentHeader extends Components.IxContentHeader {


@ProxyCmp({
inputs: ['customRangeAllowed', 'dateRangeId', 'dateRangeOptions', 'format', 'from', 'i18nCustomItem', 'i18nDone', 'i18nNoRange', 'maxDate', 'minDate', 'range', 'to'],
inputs: ['customRangeAllowed', 'dateRangeId', 'dateRangeOptions', 'disabled', 'format', 'from', 'i18nCustomItem', 'i18nDone', 'i18nNoRange', 'maxDate', 'minDate', 'range', 'to'],
methods: ['getDateRange']
})
@Component({
selector: 'ix-date-dropdown',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['customRangeAllowed', 'dateRangeId', 'dateRangeOptions', 'format', 'from', 'i18nCustomItem', 'i18nDone', 'i18nNoRange', 'maxDate', 'minDate', 'range', 'to'],
inputs: ['customRangeAllowed', 'dateRangeId', 'dateRangeOptions', 'disabled', 'format', 'from', 'i18nCustomItem', 'i18nDone', 'i18nNoRange', 'maxDate', 'minDate', 'range', 'to'],
})
export class IxDateDropdown {
protected el: HTMLElement;
Expand Down
27 changes: 27 additions & 0 deletions packages/core/component-doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,33 @@
"optional": false,
"required": false
},
{
"name": "disabled",
"type": "boolean",
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"mutable": false,
"attr": "disabled",
"reflectToAttr": false,
"docs": "Disable the button that opens the dropdown containing the date picker.",
"docsTags": [
{
"name": "since",
"text": "2.3.0"
}
],
"default": "false",
"values": [
{
"type": "boolean"
}
],
"optional": false,
"required": false
},
{
"name": "format",
"type": "string",
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ export namespace Components {
* An array of predefined date range options for the date picker. Each option is an object with a label describing the range and a function that returns the start and end dates of the range as a DateRangeOption object. Example format: { id: 'some unique id', label: 'Name of the range', from: undefined, to: '2023/03/29' }, // ... other predefined date range options ...
*/
"dateRangeOptions": DateDropdownOption[];
/**
* Disable the button that opens the dropdown containing the date picker.
* @since 2.3.0
*/
"disabled": boolean;
/**
* Date format string. See
* @link https://moment.github.io/luxon/#/formatting?id=table-of-tokens for all available tokens.
Expand Down Expand Up @@ -4591,6 +4596,11 @@ declare namespace LocalJSX {
* An array of predefined date range options for the date picker. Each option is an object with a label describing the range and a function that returns the start and end dates of the range as a DateRangeOption object. Example format: { id: 'some unique id', label: 'Name of the range', from: undefined, to: '2023/03/29' }, // ... other predefined date range options ...
*/
"dateRangeOptions"?: DateDropdownOption[];
/**
* Disable the button that opens the dropdown containing the date picker.
* @since 2.3.0
*/
"disabled"?: boolean;
/**
* Date format string. See
* @link https://moment.github.io/luxon/#/formatting?id=table-of-tokens for all available tokens.
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/components/date-dropdown/date-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export type DateRangeChangeEvent = {
export class DateDropdown {
@Element() hostElement: HTMLIxDateDropdownElement;

/**
* Disable the button that opens the dropdown containing the date picker.
*
* @since 2.3.0
*/
@Prop() disabled = false;

/**
* Date format string.
* See @link https://moment.github.io/luxon/#/formatting?id=table-of-tokens for all available tokens.
Expand Down Expand Up @@ -166,6 +173,12 @@ export class DateDropdown {
};
@State() private triggerRef: HTMLElement;

@Watch('disabled')
onDisabledChange() {
if (this.disabled) {
this.closeDropdown();
}
}
private datePickerTouched = false;

componentWillLoad() {
Expand Down Expand Up @@ -289,6 +302,7 @@ export class DateDropdown {
variant="primary"
icon="history"
ref={(ref) => (this.triggerRef = ref)}
disabled={this.disabled}
>
{this.getButtonLabel()}
</ix-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,30 @@ test('set date from a button', async ({ mount, page }) => {
const button = dateDropdown.locator('[data-date-dropdown-trigger]');
await expect(button).toHaveText(/2024\/02\/17 \- 2024\/02\/27/);
});

test('disable', async ({ mount, page }) => {
nuke-ellington marked this conversation as resolved.
Show resolved Hide resolved
await mount(`<ix-date-dropdown disabled></ix-date-dropdown>`);
const dateDropdown = page.locator('ix-date-dropdown');

const trigger = page.locator('[data-date-dropdown-trigger]');
await expect(trigger).toHaveAttribute('disabled');

await dateDropdown.click();

const dropdown = dateDropdown.locator('[data-date-dropdown]');
await expect(dropdown).not.toBeVisible();
});

test('close dropdown after disabled property = true', async ({
mount,
page,
}) => {
await mount(`<ix-date-dropdown></ix-date-dropdown>`);
const dateDropdown = page.locator('ix-date-dropdown');
await dateDropdown.click();
await dateDropdown.evaluate((dd: HTMLIxDateDropdownElement) => {
dd.disabled = true;
});
const dropdown = dateDropdown.locator('[data-date-dropdown]');
await expect(dropdown).not.toBeVisible();
});
1 change: 1 addition & 0 deletions packages/vue/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export const IxContentHeader = /*@__PURE__*/ defineContainer<JSX.IxContentHeader


export const IxDateDropdown = /*@__PURE__*/ defineContainer<JSX.IxDateDropdown>('ix-date-dropdown', defineIxDateDropdown, [
'disabled',
'format',
'range',
'from',
Expand Down
Loading