Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
refactor(sy-datepicker): improve UX and fix tests
Browse files Browse the repository at this point in the history
This reverts some changes from the past:
7a0121e
But mainly it fixes the focus handling of the input.
  • Loading branch information
derrabauke committed Dec 20, 2022
1 parent 20b197b commit 1180b9b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 13 deletions.
15 changes: 15 additions & 0 deletions app/components/sy-datepicker/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { action } from "@ember/object";
import { guidFor } from "@ember/object/internals";
import { scheduleOnce } from "@ember/runloop";
import { isTesting, macroCondition } from "@embroider/macros";
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import moment from "moment";
Expand Down Expand Up @@ -29,6 +30,13 @@ export default class SyDatepicker extends Component {
: null;
}

@action
handleFocus(dd) {
if (macroCondition(isTesting())) {
dd.actions.open();
}
}

@action
handleBlur(dd, e) {
const container = document.getElementById(
Expand Down Expand Up @@ -83,4 +91,11 @@ export default class SyDatepicker extends Component {
this.args.onChange(moment);
this.checkValidity();
}

@action
clear(dd) {
dd.actions.close();

this.args.onChange(null);
}
}
11 changes: 0 additions & 11 deletions app/components/sy-datepicker/styles.scss

This file was deleted.

22 changes: 20 additions & 2 deletions app/components/sy-datepicker/template.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<BasicDropdown @horizontalPosition="auto-right" as |DropDown|>
<DropDown.Trigger @tabindex="-1">
<DropDown.Trigger
@tabIndex="-1"
@stopPropagation={{true}}
class="sy-datepicker-trigger"
>
<input
autocomplete="off"
id={{this.uniqueId}}
Expand All @@ -9,13 +13,27 @@
pattern="\d{1,2}\.\d{1,2}\.\d{2,4}"
value={{this.displayValue}}
placeholder={{this.placeholder}}
{{on
"focus"
(prevent-default (stop-propagation (fn this.handleFocus DropDown)))
}}
{{on "blur" (fn this.handleBlur DropDown)}}
{{on "change" this.handleChange}}
{{on "input" this.checkValidity}}
/>
{{#if @value}}
<span
class="clear ember-power-select-clear-btn"
role="button"
{{on
"click"
(prevent-default (stop-propagation (fn this.clear DropDown)))
}}
>×</span>
{{/if}}
</DropDown.Trigger>

<DropDown.Content>
<DropDown.Content @class="sy-datepicker">
<SyCalendar
@center={{this.center}}
@selected={{@value}}
Expand Down
1 change: 1 addition & 0 deletions app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
@import "components/date-navigation";
@import "components/tracking-bar";
@import "components/sy-calendar";
@import "components/sy-datepicker";

html {
hyphens: auto;
Expand Down
15 changes: 15 additions & 0 deletions app/styles/components/sy-datepicker.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.sy-datepicker-trigger.ember-basic-dropdown-trigger {
position: relative;

span.clear {
cursor: pointer;
color: #555;
line-height: 1.5;
font-size: 0.9rem;
background-color: #fff;
padding: 0 2px;
right: 0.75rem;
top: 50%;
transform: translateY(-50%);
}
}

0 comments on commit 1180b9b

Please sign in to comment.