]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Add check if key exists in map 8972/head
authorChris Thronebury <cthronebury@gmail.com>
Sun, 26 Jun 2016 15:20:53 +0000 (11:20 -0400)
committerChris Thronebury <cthronebury@gmail.com>
Sun, 26 Jun 2016 15:20:53 +0000 (11:20 -0400)
scss/util/_breakpoint.scss

index ddcf80aa0313db174d9bd5206854ad1de08c5033..3e5a898273d152abc7ddc9db170cd8ac9fa2a7ca 100644 (file)
@@ -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.