Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBen Hobgood
1,791 PointsMy solution for javascript list (disabling functionality buttons)
My Solution: https://w.trhou.se/olqht3o4o9
I personally didn't like the idea of a visual jump of buttons being added and created. I felt like it would give me a head ache to watch the buttons jump around. Additionally it would be a bad user experience if Up could be positioned where Down usually is. So instead I opted to 'gray out' and disable the buttons at the top and the bottom of the list.
Change Log from Original Script:
- Refactored repeated code in Button creation to be an arrow function.
- Created two functions to handle disabling & activating buttons.
- Created a function to crawl through the list and then adds buttons if they need to be added and updates the buttons to reflect the list item's position ( could be optimized further for performance).
- Created a function to create new list items
- Created a new event listener that adds a list item on hitting the 'return' key within the input field.
- Added crawl function to events to initialization of script & any listeners that affected order (addition / movement / subtraction)
1 Answer
Steven Parker
231,261 PointsNice enhancements! I also found that simply disabling the buttons created a more pleasant UX.
A couple of minor things I spotted in the code:
- you don't need to use explicit css changes when you disable unless you don't like the default "dimmed" look
-
I don't think "cssText" (line 26) is actually a "style" propertyturns out it is!
Ben Hobgood
1,791 PointsBen Hobgood
1,791 PointsHey Steven. Thanks for the feedback. I was applying the style changes for visual reasons and cssText was used to wipe out the inline stylings I was using by setting the style attribute to blank. I wasn't sure of a better way to reset the button other then using class names to toggle between styles.
Steven Parker
231,261 PointsSteven Parker
231,261 PointsYou taught me something new! I was not previously aware of the properties of a CSSStyleDeclaration other than the style properties themselves.
And my comment about the default disabled appearance doesn't apply since these buttons are not using the default appearance.