From fd669cac6a955520f3f387c0e45f851ff9cee5af Mon Sep 17 00:00:00 2001 From: Chris Thronebury Date: Sun, 26 Jun 2016 11:20:53 -0400 Subject: [PATCH] Add check if key exists in map --- scss/util/_breakpoint.scss | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scss/util/_breakpoint.scss b/scss/util/_breakpoint.scss index ddcf80aa0..3e5a89827 100644 --- a/scss/util/_breakpoint.scss +++ b/scss/util/_breakpoint.scss @@ -175,21 +175,26 @@ $breakpoint-classes: (small medium large) !default; /// /// @returns {Mixed} The value for the key after `$key`, if `$key` was found. If `$key` was not found, or `$key` was the last value in the map, returns `null`. @function -zf-map-next($map, $key) { - // Store the values of the map as a list, so we can access them with nth + + // Store the keys of the map as a list $values: map-keys($map); - // Get the index of the key within the map and add 1 to it for the next breakpoint in the map - $i: index($values, $key) + 1; + $i: 0; + + // If the Key Exists, Get the index of the key within the map and add 1 to it for the next breakpoint in the map + @if (map-has-key($map, $key)) { + $i: index($values, $key) + 1; + } // If the key doesn't exist, or it's the last key in the map, return null - @if $i > length($map) { + @if ($i > length($map) or $i == 0) { @return null; } // Otherwise, return the value @else { @return map-get($map, nth($values, $i)); - } + } /// Get a value for a breakpoint from a responsive config map. If the config map has the key `$value`, the exact breakpoint value is returned. If the config map does *not* have the breakpoint, the value matching the next lowest breakpoint in the config map is returned. -- 2.47.2