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

Previous Month Button not disabled in DatePicker #6541

Open
laundy opened this issue Mar 30, 2020 · 0 comments
Open

Previous Month Button not disabled in DatePicker #6541

laundy opened this issue Mar 30, 2020 · 0 comments

Comments

@laundy
Copy link

laundy commented Mar 30, 2020

Expected Behavior

If minYear and maxYear are provided, the .is-disabled class should be added to both arrow buttons and they should not be clickable anymore.

Current Behavior

The .is-disabled class is only added to the rightArrow (next) and both buttons are always clickable.

Possible Solution

Two things are not working as expected. First, the class .is-disabled is only added to the next month button. I've identified the line of code that is causing this and realized that the statements seem to be in the wrong order for the leftArrow (see comment in code):

var leftArrow = '<svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M15.41 16.09l-4.58-4.59 4.58-4.59L14 5.5l-6 6 6 6z"/><path d="M0-.5h24v24H0z" fill="none"/></svg>';
html += "<button class=\"month-prev" + (prev ? '' : ' is-disabled') + "\" type=\"button\">" + leftArrow + "</button>";

html += '<div class="selects-container">';
if (opts.showMonthAfterYear) {
  html += yearHtml + monthHtml;
} else {
  html += monthHtml + yearHtml;
}
html += '</div>';

// this if must be evaluated before leftArrow is initialized because otherwise prev will always be true or initialization of leftArrow must happen later
if (isMinYear && (month === 0 || opts.minMonth >= month)) {
  prev = false;
}

if (isMaxYear && (month === 11 || opts.maxMonth <= month)) {
  next = false;
}

var rightArrow = '<svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"/><path d="M0-.25h24v24H0z" fill="none"/></svg>';
html += "<button class=\"month-next" + (next ? '' : ' is-disabled') + "\" type=\"button\">" + rightArrow + "</button>";

Furthermore, the .is-disabled class doesn't has an impact on the two buttons because a matching CSS rule is missing. An example rule that shows the expected behavior would be:

button.is-disabled {
  visibility: hidden;
  pointer-events: none;
}

Steps to Reproduce (for bugs)

JSFiddle link: https://jsfiddle.net/guc3sjzh/

  1. Open datepicker by clicking on the input field
  2. The back button does not have the .is-disabled class and is clickable despite the minYear is 1970 and the button should be disabled while being in January 1970.
  3. Go to year 2010 (maxYear) and month December. The button does have the .is-disable class but is still clickable.

Context

The buttons staying visible is misleading for the user because it is not clear that (s)he reached the minYear or maxYear. Furthermore, the behavior is inconsistent with the documentation and the implementation itself (leftArrow vs. rightArrow).

Your Environment

Materialize 1.0.0, tested in Google Chrome

  • Version used: 1.0.0
  • Browser Name and version: Google Chrome 80.0.*
  • Operating System and version (desktop or mobile): Windows 10 1909 (Desktop)
  • Link to your project (if appropriate): https://jsfiddle.net/guc3sjzh/ (example)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant